2011-10-06 105 views
1

我試圖使用JS SDK或圖API發送應用程序生成的請求,但我並不成功,絕望。問題是,當我向當前登錄的用戶發送請求時,一切正常,但是當我嘗試發送給不同的用戶時(即使此用戶已經授權我的應用),我收到OAuth異常「#2用戶無法發送此請求:未知錯誤「,有時」無法發送任何應用程序請求「。向「/ me」以外發送請求2.0應用程序生成的請求

我的應用程序已啓用請求2.0,並授權publish_stream,read_stream和user_about_me權限。即使在Graph API瀏覽器中也會顯示我描述的相同錯誤消息。

完全相同的問題在這裏描述了使用JS SDK: Sending an App Generated Request with the JavaScript SDK

...這裏使用圖形API: Posting app generated apprequest to other facebook users in Java

請幫助。

+0

如何選擇要向其發送請求的用戶?以及您正在使用的代碼? –

+0

這樣使用JS SDK: FB.api(「/」+ recipient +「/ apprequests」,「POST」,{message:「Notification Message」,data:「Notification data」},function(response){console。 log(response);}); – Edgar

+0

[使用JavaScript SDK發送應用程序生成的請求]的可能重複(http://stackoverflow.com/questions/7496981/sending-an-app-generated-request-with-the-javascript-sdk) – genesis

回答

0

如果要向用戶發送請求,則應使用應用程序訪問令牌(https://developers.facebook.com/docs/authentication/#applogin)將其發佈到Graph API'/ user_id/apprequests' 。該調用是設計要執行服務器端,你不希望分享您的應用程序訪問令牌:

curl -F 'access_token=APP_ACCESS_TOKEN' \ 
-F 'message=From the app to the user.' \ 
https://graph.facebook.com/USER_ID/apprequests 

同樣可以實現使用用戶訪問令牌從收件人(USER_ID)只:

curl -F 'access_token=USER_ACCESS_TOKEN' \ 
-F 'message=From the app to the user.' \ 
https://graph.facebook.com/USER_ID/apprequests 

在JS SDK,如不加訪問令牌字段,默認的訪問令牌將登錄的用戶的。知道的是,上述呼叫,其發送一個請求到登錄的用戶,將是:

FB.api('/me/apprequests', 'POST', {message: 'From the app to the user.'}); 

第一呼叫也可與JS SDK完成的,通過在參數添加應用程序訪問令牌。但是,這是一個不用用例,因爲您不想共享您的App Access令牌客戶端。