0

我正在使用 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}}

任何建议,将不胜感激。谢谢

4

1 回答 1

0

但是,没有发送访问令牌,是吗?尝试类似:

String token = getAccessToken();

if (token){
    parameters.putString("access_token", token);
    String response = mFacebook.request("me/feed",parameters,"POST");
} else {
    // Log the user in
}
于 2012-09-16T12:45:08.113 回答