简体   繁体   English

Facebook API添加照片

[英]facebook API add photo

I need to post a Bitmap to Facebook wall along with a message and url link. 我需要将Bitmap以及消息和URL链接发布到Facebook墙上。

According to https://developers.facebook.com/docs/reference/api/user/#photos , there are 4 parameters to add a photo to Facebook album: 根据https://developers.facebook.com/docs/reference/api/user/#photos ,有4个参数可将照片添加到Facebook相册:

source , message , place , no_story . sourcemessageplaceno_story

However, I was recommend to use a code like this: 但是,建议我使用如下代码:

Bitmap bm = ...;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 100, baos);
final byte[] data = baos.toByteArray();
Bundle postParams = new Bundle();

postParams.putByteArray("photo", data);
postParams.putString("message", "My message here");
postParams.putString("link", "http://www.google.com");

Request request = new Request(session, "me/photos", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();

... and this code works fine except it does not show the link ("http://www.google.com") on the wall. ...,并且此代码可以正常工作,但它不会在墙上显示链接(“ http://www.google.com”)。

I have three questions: 我有三个问题:

  1. Why does postParams.putByteArray("photo", data) work? 为什么postParams.putByteArray("photo", data)起作用? There's no photo parameter according to documentation (see above). 根据文档,没有photo参数(请参见上文)。

  2. If it is impossible to use link parameter, how does SLComposeViewController class (http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html) work? 如果不可能使用link参数,SLComposeViewController类(http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html)如何工作? It has - (BOOL)addURL:(NSURL *)url method. 它具有- (BOOL)addURL:(NSURL *)url方法。

  3. If it is possible to use link parameter, why doesn't it work? 如果可以使用link参数,为什么它不起作用?

Okay, I found answers to questions (2) and (3). 好的,我找到了问题(2)和(3)的答案。 It appeared to be very simple: do not use link , just append it to message : 它看起来非常简单:不使用link ,只需将其附加到message

postParams.putByteArray("photo", data);
postParams.putString("message", "My message here" + " " + "http://www.google.com");
//postParams.putString("link", "http://www.google.com");

As for my question (1), it is still unclear for me: why does postParams.putByteArray("photo", data); 至于我的问题(1),对我来说还不清楚:为什么postParams.putByteArray("photo", data); work fine instead of postParams.putByteArray("source", data); 工作正常,而不是postParams.putByteArray("source", data); ? The documentation say nothing about photo parameter. 该文档对photo参数一无所知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM