[英]Android, issue in posting message on my wall on Facebook
我正在使用Facebook SDK,並且想在牆上張貼消息。 我耕種互聯網已經快兩天了,但是我沒有成功找到問題所在。 讓我說說我做了什么。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Try to create activity...");
// Close activity if app id is not specified.
if (FACEBOOK_APPID == null || FACEBOOK_APPID == "") {
Log.e(TAG, "Facebook Applicaton ID must be specified before running this screen.");
closeActivity();
}
// Getting extra info which is passed by caller activity.
// If we are here by mistake(Caller didn't send required parameter) close activity.
Bundle extras = getIntent().getExtras();
if(extras == null) {
Log.i(TAG, "No data passed to this activity. Activity closed.");
closeActivity();
}
// Get Message
message = extras.getString("FB_WALLPOST");
// Log.i(TAG, "message>>> " + message);
mFacebook = new Facebook(FACEBOOK_APPID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
SessionStore.restore(mFacebook, this);
SessionEvents.addAuthListener(new SampleAuthListener());
SessionEvents.addLogoutListener(new SampleLogoutListener());
// mFacebook.dialog(FacebookActivity.this, "feed", params, new SampleDialogListener());
Thread thread = new BasicThread();
thread.start();
}
根據我的研究,我發現Facebook.dialog
無法使用。 這就是為什么它被注釋掉的原因。 我還發現我們需要使用Facebook.request
代替它。 我發現Note that this method blocks waiting for a network response, so do not call it in a UI thread.
在SDK中的實現中。 因此,我創建了另一個線程來處理發布過程。
當線程啟動時,將調用以下方法。
public class BasicThread extends Thread {
public void run() {
try{
Bundle parameters = new Bundle();
parameters.putString("message", "Text is lame. Listen up:");
parameters.putString("name", "Name");
parameters.putString("link", "http://www.google.com");
parameters.putString("caption", "Caption");
parameters.putString("description", "Description");
String response = mFacebook.request("me/feed",parameters,"POST");
Log.v("response", response);
}
catch(Exception e){}
}
}
那些建議該代碼的人被告知該方法對他們有效。 但是,我不知道為什么它對我不起作用。
在logcat中的響應:
09-16 17:06:21.860: D/Facebook-Util(26652): POST URL: https://graph.facebook.com/me/feed
09-16 17:06:23.350: V/response(26652): {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
任何建議,將不勝感激。 謝謝
但是,沒有發送訪問令牌嗎? 嘗試類似:
String token = getAccessToken();
if (token){
parameters.putString("access_token", token);
String response = mFacebook.request("me/feed",parameters,"POST");
} else {
// Log the user in
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.