使用PhoneGap从iPhone摄像头向FaceBook墙上发布图像
我正在使用PhoneGap从iPhone向FaceBook墙发布图像 我可以登录FaceBook帐户并发布托管图像(使用PhoneGap从iPhone摄像头向FaceBook墙上发布图像,iphone,image,facebook,cordova,publish,Iphone,Image,Facebook,Cordova,Publish,我正在使用PhoneGap从iPhone向FaceBook墙发布图像 我可以登录FaceBook帐户并发布托管图像(http://www.mysite.com/my_image.jpg)但不是来自iPhone的图像 以下是要发布到FB的脚本: function fbPost() { $.ajax({ type: 'POST', url: "https://graph.facebook.com/me/feed", data:
http://www.mysite.com/my_image.jpg
)但不是来自iPhone的图像
以下是要发布到FB的脚本:
function fbPost() {
$.ajax({
type: 'POST',
url: "https://graph.facebook.com/me/feed",
data: {
message: "<FACEBOOK MESSAGE>",
PICTURE: "<IMAGE URL>",
name: "<TITLE OF POST>",
link: "<LINK TO APP>",
caption: "<SHOWN BELOW TITLE>",
description: "<SHOWN BELOW CAPTION>",
access_token: access_token,
format: "json"
},
success: function (data) {
navigator.notification.alert("success!", null, "Thanks!")
},
},
dataType: "json",
timeout: 10000
})
}
()
当我使用iPhone中的图像时,图像的URI类似于:
file:///var/mobile/Applications/..../Documents/tmp/photo_001.jpg
同样,当我指定一个托管(http://...
)图像,但不是来自iPhone的图像
我非常感激任何帮助
多谢各位
RobFacebook无法访问您电话上的本地文件。我不知道如何将照片上传到facebook,但正如你之前所说的,如果你使用公共托管文件,它就会起作用 所以我认为你有两个选择: 将foto上传到服务器,然后将文件的url发布到facebook。(你可以使用phonegap的文件api来实现这一点,这里有一个上传插件),但我认为这并不是一个好的解决方案
我建议您查找是否可以将图像数据发布到facebook(可能是base64编码的),并使用phonegap api获取foto的base64编码内容,并将其直接发布到facebookfacebook无法访问您电话上的本地文件。我不知道如何将照片上传到facebook,但正如你之前所说的,如果你使用公共托管文件,它就会起作用 所以我认为你有两个选择: 将foto上传到服务器,然后将文件的url发布到facebook。(你可以使用phonegap的文件api来实现这一点,这里有一个上传插件),但我认为这并不是一个好的解决方案
我建议您将图像数据发布到facebook(可能是base64编码的),并使用phonegap api获取foto的base64编码内容,然后将其直接发布到facebook我编写了一个phonegap插件,用于将照片从iPhone/iPad发布到facebook。此插件还可以发布带有Facebook place id的照片(意味着它可以使用照片签入Facebook),并且在iOS 6.0上运行良好 它基于PhoneGap 2.1,并且不需要任何中间主机,也许它可以解决您的问题;) 首先,光电检测.h是
#import <Foundation/Foundation.h>
#import "Facebook.h"
#import "FBConnect.h"
#import <Cordova/CDV.h>
@interface PhotoCheckin : CDVPlugin
<FBDialogDelegate>
- (void) sendPost:(CDVInvokedUrlCommand*)command;
@end
注意:此方法在发布时会回调,一些代码行被注释掉,这可以向用户发出警报
第三,PhotoCheckin.js如下所示
#import "PhotoCheckin.h"
#import "FBSBJSON.h"
@implementation PhotoCheckin
- (void) sendPost:(CDVInvokedUrlCommand*)command {
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[command.arguments objectAtIndex:0]]]];
NSString* message = [command.arguments objectAtIndex:1];
NSString* place_id = [command.arguments objectAtIndex:2];
NSLog(@"%@",message);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image, @"source",message,@"message",place_id, @"place", nil];
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startWithGraphPath:@"me/photos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *resultStr = nil;
if (error) {
//resultStr = [NSString stringWithFormat:@"error: domain = %@, code = %d",error.domain, error.code];
resultStr = [[CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:[NSString stringWithFormat:@"error: domain = %@, code = %d",error.domain, error.code]] toErrorCallbackString:command.callbackId];
}else{
//resultStr = [NSString stringWithFormat:@"Posted action, id: %@",[result objectForKey:@"id"]];
resultStr = [[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"Posted action, id: %@",[result objectForKey:@"id"]]] toSuccessCallbackString:command.callbackId];
}
//[[[UIAlertView alloc] initWithTitle:@"Check-in Result" message:resultStr delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
[self writeJavascript:resultStr];
}];
}else{
NSLog(@"no active session");
NSArray *permissions = [[NSArray alloc] initWithObjects:@"publish_stream",nil];
// more "permissions strings" at http://developers.facebook.com/docs/authentication/permissions/
// OPEN Session
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (FB_ISSESSIONOPENWITHSTATE(status)) {
[[[UIAlertView alloc] initWithTitle:@"Got FB session!" message:@"please check-in again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}else{
[self writeJavascript:[[CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:[NSString stringWithFormat:@"error: domain = %@, code = %d",error.domain, error.code]] toErrorCallbackString:command.callbackId]];
/*[[[UIAlertView alloc] initWithTitle:@"Login Fail"
message:[NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil]
show];*/
}
}];
}
}
@end
var PhotoCheckin = {
sendPost: function(photo_uri, message, place_id, success, fail) {
return Cordova.exec(success, fail, "PhotoCheckin", "sendPost", [photo_uri, message, place_id]);
}
}
最后,当我们使用插件时,我们编写js如下。(in.html/.js)
注意:照片的uri是照片的uri(例如。file:///...),消息是用户的评论,地点id是Facebook上的地点id(例如106522332718569)
和其他插件一样,我们必须编辑Resources/Cordova.plist,在插件中添加photoCheckin作为键和photoCheckin作为值。并将PhotoCheckin.h和PhotoCheckin.m放入名为Plugins的文件夹,在js代码中包含PhotoCheckin.js文件
玩得开心!从…起台灣 :) 我编写了一个PhoneGap插件,用于将照片从iPhone/iPad发布到Facebook。此插件还可以发布带有Facebook place id的照片(意味着它可以使用照片签入Facebook),并且在iOS 6.0上运行良好 它基于PhoneGap 2.1,并且不需要任何中间主机,也许它可以解决您的问题;) 首先,光电检测.h是
#import <Foundation/Foundation.h>
#import "Facebook.h"
#import "FBConnect.h"
#import <Cordova/CDV.h>
@interface PhotoCheckin : CDVPlugin
<FBDialogDelegate>
- (void) sendPost:(CDVInvokedUrlCommand*)command;
@end
注意:此方法在发布时会回调,一些代码行被注释掉,这可以向用户发出警报
第三,PhotoCheckin.js如下所示
#import "PhotoCheckin.h"
#import "FBSBJSON.h"
@implementation PhotoCheckin
- (void) sendPost:(CDVInvokedUrlCommand*)command {
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[command.arguments objectAtIndex:0]]]];
NSString* message = [command.arguments objectAtIndex:1];
NSString* place_id = [command.arguments objectAtIndex:2];
NSLog(@"%@",message);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image, @"source",message,@"message",place_id, @"place", nil];
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startWithGraphPath:@"me/photos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *resultStr = nil;
if (error) {
//resultStr = [NSString stringWithFormat:@"error: domain = %@, code = %d",error.domain, error.code];
resultStr = [[CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:[NSString stringWithFormat:@"error: domain = %@, code = %d",error.domain, error.code]] toErrorCallbackString:command.callbackId];
}else{
//resultStr = [NSString stringWithFormat:@"Posted action, id: %@",[result objectForKey:@"id"]];
resultStr = [[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"Posted action, id: %@",[result objectForKey:@"id"]]] toSuccessCallbackString:command.callbackId];
}
//[[[UIAlertView alloc] initWithTitle:@"Check-in Result" message:resultStr delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
[self writeJavascript:resultStr];
}];
}else{
NSLog(@"no active session");
NSArray *permissions = [[NSArray alloc] initWithObjects:@"publish_stream",nil];
// more "permissions strings" at http://developers.facebook.com/docs/authentication/permissions/
// OPEN Session
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (FB_ISSESSIONOPENWITHSTATE(status)) {
[[[UIAlertView alloc] initWithTitle:@"Got FB session!" message:@"please check-in again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}else{
[self writeJavascript:[[CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:[NSString stringWithFormat:@"error: domain = %@, code = %d",error.domain, error.code]] toErrorCallbackString:command.callbackId]];
/*[[[UIAlertView alloc] initWithTitle:@"Login Fail"
message:[NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil]
show];*/
}
}];
}
}
@end
var PhotoCheckin = {
sendPost: function(photo_uri, message, place_id, success, fail) {
return Cordova.exec(success, fail, "PhotoCheckin", "sendPost", [photo_uri, message, place_id]);
}
}
最后,当我们使用插件时,我们编写js如下。(in.html/.js)
注意:照片的uri是照片的uri(例如。file:///...),消息是用户的评论,地点id是Facebook上的地点id(例如106522332718569)
和其他插件一样,我们必须编辑Resources/Cordova.plist,在插件中添加photoCheckin作为键和photoCheckin作为值。并将PhotoCheckin.h和PhotoCheckin.m放入名为Plugins的文件夹,在js代码中包含PhotoCheckin.js文件
玩得开心!从…起台灣 :) 谢谢你,丹尼尔。PhoneGap API可以选择将捕获的图像作为base64编码字符串获取:
document.getElementById('image').src=“data:image/jpeg;base64,”+imageData代码>但它也不起作用。至少当我把picture:“document.getElementById('image').src”
放到facebook api上时,我快速查看了一下,他们只接受一个url。所以你需要上传图片。在这里可以找到一个很好的方法:谢谢你,丹尼尔。PhoneGap API可以选择将捕获的图像作为base64编码字符串获取:document.getElementById('image').src=“data:image/jpeg;base64,”+imageData代码>但它也不起作用。至少当我把picture:“document.getElementById('image').src”
放到facebook api上时,我快速查看了一下,他们只接受一个url。所以你需要上传图片。在这里可以找到一个很好的方法:那么,是什么让您能够在手机上发布图像(而不仅仅是托管图像)?如果你的回答能解释这一点,那就好了。就像其他原生objective-C iOS应用程序可以通过Graph API()将本地照片发布到FB一样,我使用原生代码来处理照片上传:)那么,是什么使手机上能够发布图像(而不仅仅是托管图像)?如果你的答案能解释这一点就好了。就像其他原生objective-C iOS应用程序可以通过Graph API()将本地照片发布到FB一样,我使用原生代码来处理照片上传:)