Android,在Facebook上发布消息发布在我的墙上

时间:2012-09-16 09:08:39

标签: android facebook sdk sharing

我正在使用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而不是那个。我在SDK中的实现中找到了Note that this method blocks waiting for a network response, so do not call it in a UI thread.。因此,我创建了另一个线程来处理发布过程。

当线程开始跟随方法时,将调用。

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}}

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

1 个答案:

答案 0 :(得分:0)

不会发送任何访问令牌,不是吗? 尝试类似:

String token = getAccessToken();

if (token){
    parameters.putString("access_token", token);
    String response = mFacebook.request("me/feed",parameters,"POST");
} else {
    // Log the user in
}