我試圖讓已經鏈接其Facebook帳戶的用戶能夠通過一個按鈕按下detailed in their docs來發布到他們的牆上。具體來說,我不想使用Facebook for Android library中提供的.dialog方法,因爲我希望發佈過程儘可能無縫。從Android應用程序發佈到Facebook訂閱源
特定呼叫看起來像這樣在HTTP客戶端模擬器:
HTTP POST
https://graph.facebook.com/me/feed
內容類型:應用/ X WWW的窗體-urlencoded
的access_token = ... &鏈接= http://mylink.com/id/1326&name=What做您認爲? &描述=鏈接
此調用的說明成功地運行在HTTP客戶端在OS X
我最初試圖使用Facebook的Android庫與「stream.publish」行動.dialog功能,但是這會導致不想要的對話框出現。
接下來,我嘗試使用Facebook的Android的.request函數與「POST」參數,但此函數假定正文是一個字節數組,並在庫中的多個位置失敗。
現在,我正在嘗試使用Android中包含的Apache HTTP堆棧。 具體來說,我的代碼看起來是這樣的:
String url = "https://graph.facebook.com/me/feed";
ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>(4);
pairs.add(new BasicNameValuePair("access_token", App.facebook.getAccessToken()));
pairs.add(new BasicNameValuePair("link", "http://mylink.com/id/"+id));
pairs.add(new BasicNameValuePair("name", question));
pairs.add(new BasicNameValuePair("description", description));
InputStream inputStream = null;
HttpResponse response = null;
HttpClient client = null;
try {
final HttpPost post = new HttpPost(url);
final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs);
post.setEntity(entity);
client = new DefaultHttpClient();
response = client.execute(post);
} catch (IOException e) {
// code to handle exceptions
}
// close streams, etc.
的問題是,從Facebook的反應是一致的以下內容:
{"error":{"type":"OAuthException","message":"Invalid OAuth access token."}}
我知道OAuth訪問令牌是不是無效的。當我將相同的OAuth訪問令牌粘貼到HTTP客戶端時,它就像冠軍一樣。看起來創建HttpPost對象的參數是以某種方式篡改複雜的OAuth訪問令牌。有沒有人有如何進行的建議?
你在Facebook的 – 2011-09-26 10:03:05