使用 PhoneGap 将 iPhone 相机胶卷中的图像发布到 Facebook 墙
我正在使用 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: {
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 获取图像(相机胶卷或相册)的代码:
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI });
function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;
}
(http://docs.phonegap.com/phonegap_camera_camera.md.html)。
当我使用 iPhone 中的图像时,图像的 URI 类似于: file:///var/mobile/Applications/..../Documents/tmp/photo_001.jpg
同样,当我指定托管 (http: //...
) 图像,但当它是来自 iPhone 的图像时则不然。
我将非常感谢任何帮助。
谢谢。
抢
I am using PhoneGap to publish an image to a FaceBook wall from an iPhone.
I am able to log in a FaceBook account and publish a HOSTED image (http://www.mysite.com/my_image.jpg
) but not an image from the iPhone.
Here is the script to post to 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
})
}
Here is the code to get an image from the iPhone (camera roll or album):
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI });
function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;
}
(http://docs.phonegap.com/phonegap_camera_camera.md.html).
When I use an image from the iPhone, the URI of the image is something like:file:///var/mobile/Applications/..../Documents/tmp/photo_001.jpg
Again, I am able to publish an image when I specify a hosted (http://...
) image, but not when it's an image from the iPhone.
I would greatly apreciate any help.
Thank you.
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Facebook 无法访问您手机上的本地文件。我不知道如何将照片上传到 Facebook,但正如您之前所说,如果您使用公共托管文件,它就可以工作。
所以我认为你在这里有两个选择:
将照片上传到服务器,然后将文件的 URL 发布到 Facebook。 (你可以使用phonegap的文件api来做到这一点,有一个上传插件的事件),但我认为这并不是一个很好的解决方案。
我建议您查找是否可以将图像数据发布到facebook(可能是base64编码)并使用phonegap api获取照片的base64编码内容并将其直接发布到facebook
Facebook can not access a local file on your telephone. I dont know about the ways you can upload a photo to facebook, but as you said before it works if you use a public hosted file.
So I think you got two choices here:
Upload the foto to a server an then post the url of the file to facebook. (you can use the file api of phonegap to do that, theres event an upload plugin), but i think this is not really a good solution.
I would suggest to find if you can post the image data to facebook (maybe base64 encoded) and use the phonegap api to get the base64 encoded content of the foto and post this directly to facebook
我编写了一个 PhoneGap 插件,使用 Graph API 将 iPhone/iPad 中的照片发布到Facebook。该插件还可以发布带有 Facebook 地点 ID 的照片(意味着它可以使用照片签入 Facebook),并且在 iOS 6.0 上运行良好。
它基于 PhoneGap 2.1 和 phonegap-plugin-facebook-connect,以及 不需要任何中间主机,也许它可以解决你的问题;)
首先,PhotoCheckin.h是...
其次,PhotoCheckin.m如下。
注:该方法发布时会回调,部分代码行被注释掉,可以提醒用户。
第三,PhotoCheckin.js如下。
最后我们去使用插件的时候,编写js如下。 (在 .html/.js 中)
注意:photo_uri 是照片的 uri(例如 file:///...),message 是用户的评论,place_id 是 Facebook 中的地点 ID(例如 106522332718569)。
与其他插件一样,我们必须编辑 Resources/Cordova.plist,在插件中添加 photoCheckin 作为键,添加 PhotoCheckin 作为值。并将PhotoCheckin.h和PhotoCheckin.m放入名为Plugins的文件夹中,在您的文件中包含PhotoCheckin.js文件js 代码。
玩得开心!来自台湾:)
I write a PhoneGap plug-in use Graph API to post photos from iPhone/iPad to Facebook. This plug-in can also post photo with Facebook place id (means it can Checkin Facebook with photo) and works fine on iOS 6.0.
It's based on PhoneGap 2.1 and phonegap-plugin-facebook-connect, and not need any middle host, maybe it can solve your problem ;)
First, the PhotoCheckin.h is...
Second, PhotoCheckin.m as follow.
Notes: this method will callback when posted, some code lines were commented out, which can make alert to users.
Third, the PhotoCheckin.js as follow.
Finally, when we went to use the plug-in, we write js as follow. (in .html/.js)
Notes: photo_uri is the photo's uri (e.g. file:///...), message is user's comment and place_id is the place id in Facebook (e.g. 106522332718569).
And like other plug-ins, we must to edit Resources/Cordova.plist, add photoCheckin as key and PhotoCheckin as value in plugins. And put PhotoCheckin.h&PhotoCheckin.m to folder named Plugins, include PhotoCheckin.js file in your js code.
have fun! from 台灣 :)