繁体   English   中英

Android,在我的Facebook墙上张贴消息时出现问题

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM