使用Facebook Android SDK在Facebook墙上张贴而不打开对话框 [英] Post on Facebook wall using Facebook Android SDK without opening dialog box

查看:112
本文介绍了使用Facebook Android SDK在Facebook墙上张贴而不打开对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Facebook SDK,我可以登录access_token并将其存储到数据库中.当我尝试创建帖子时,由于以下问题,我的手机和模拟器上的Facebook墙仍然是空的:

Using the Facebook SDK, I can login and store my access_token into a database. When I try to create a post, the Facebook wall is still empty on both my phone and emulator due to these problems:

1)我从数据库中获取了access_token并将access_token传递给了Facebook,但是我不允许在墙上发帖.

1) I fetch an access_token from the database and pass the access_token to Facebook, but I'm not allowed to post on a wall.

2)我无法在不打开对话框的情况下发布消息.

2) I cannot post my message without opening a dialog box.

   mPostButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                String message = "Post this to my wall";

                Bundle params = new Bundle();             

                params.putString("message", message);

                mAsyncRunner.request("me/feed", params, "POST", new WallPostRequestListener());

            }
        });

 public class WallPostRequestListener extends BaseRequestListener {

        public void onComplete(final String response) {
            Log.d("Facebook-Example", "Got response: " + response);
            String message = "<empty>";
            try {
                JSONObject json = Util.parseJson(response);
                message = json.getString("message");
            } catch (JSONException e) {
                Log.w("Facebook-Example", "JSON Error in response");
            } catch (FacebookError e) {
                Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
            }
            final String text = "Your Wall Post: " + message;
            Example.this.runOnUiThread(new Runnable() {
                public void run() {
                    mText.setText(text);
                }
            });
        }
    }

如何在不打开对话框的情况下发布到Facebook?

How can I post to Facebook without opening the dialog box?

推荐答案

我应用了以下代码,并且可以成功地将我的消息发布在墙上.

i applied following code and could successfully posted my message on wall.

public void postOnWall(String msg) {
        Log.d("Tests", "Testing graph API wall post");
         try {
                String response = mFacebook.request("me");
                Bundle parameters = new Bundle();
                parameters.putString("message", msg);
                parameters.putString("description", "test test test");
                response = mFacebook.request("me/feed", parameters, 
                        "POST");
                Log.d("Tests", "got response: " + response);
                if (response == null || response.equals("") || 
                        response.equals("false")) {
                   Log.v("Error", "Blank response");
                }
         } catch(Exception e) {
             e.printStackTrace();
         }
    }

这篇关于使用Facebook Android SDK在Facebook墙上张贴而不打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆