android在facebook sdk 3.0.2上分享

时间:2013-07-31 09:39:17

标签: android facebook facebook-graph-api

我想在Facebook上使用android facebook sdk 3.0.2

分享一些文字

我试过这个:

Bundle params = new Bundle();
                params.putString("caption", "test");
                params.putString("message", "test");
                params.putString("link", "https://www.google.com");
                // params.putString("picture", "picture_url");

                Request request = new Request(Session.getActiveSession(),
                        "me/feed", params, HttpMethod.POST);
                request.setCallback(new Request.Callback() {
                    @Override
                    public void onCompleted(Response response) {
                        if (response.getError() == null) {
                            Toast.makeText(About.this, "Successfully posted",
                                    Toast.LENGTH_LONG).show();
                        } else
                            Toast.makeText(About.this, "An Error Has Happened",
                                    Toast.LENGTH_SHORT).show();
                    }
                });
                request.executeAsync();
            }

toast总是打印an error has happened

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

    Session s = Session.getActiveSession();

Request request = Request.newStatusUpdateRequest(s, "your msg", new Request.Callback() 
    {
        @Override
        public void onCompleted(Response response)
        {
            if(response.getError()==null) 
                Toast.makeText(MainActivity.this, "Status updated successfully", Toast.LENGTH_LONG).show();

        }
    });
    request.executeAsync();

如果您已登录并已提供所有权限,则会发布您的消息。