2012-11-14 87 views
1

我需要發佈位圖到Facebook牆以及消息和url鏈接。facebook API添加照片

https://developers.facebook.com/docs/reference/api/user/#photos,有4個參數的照片添加到Facebook的相冊:

sourcemessageplaceno_story

不過,我建議使用這樣的代碼:

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(); 

...這代碼工作正常,但它並沒有顯示鏈接(「http://www.google.com」 ) 在牆壁上。

我有三個問題:

  1. 爲什麼postParams.putByteArray("photo", data)工作?根據文檔,沒有photo參數(參見上文)。

  2. 如果無法使用link參數,如何SLComposeViewController類(http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html)工作?它有- (BOOL)addURL:(NSURL *)url方法。

  3. 如果可以使用link參數,爲什麼它不起作用?

回答

0

好的,我找到了問題(2)和(3)的答案。這似乎是很簡單的:不使用link,只是將其追加到message

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

至於我的問題(1),目前還不清楚我:爲什麼postParams.putByteArray("photo", data);做工精細,而不是postParams.putByteArray("source", data);?該文檔沒有提到photo參數。