用户使用Facebook登录Android应用程序时设置发布状态权限

时间:2013-08-05 09:09:30

标签: android facebook-graph-api facebook-sdk-3.0

我想将权限设置为代表用户在墙上发布。当用户使用facebook登录时,会出现如下对话框。当用户点击确定时,他应该可以在帖子上发帖。 enter image description here

我试过这个....这是我的代码..请帮助我

LoginButton authButton = (LoginButton) findViewById(R.id.authButton);
          authButton.setOnErrorListener(new OnErrorListener() {

       @Override
       public void onError(FacebookException error) {
        Log.i(TAG, "Error " + error.getMessage());
       }
      });
      // set permission list, Don't foeget to add email
      authButton.setReadPermissions(Arrays.asList("basic_info","email","user_status"));
      // session state call back event
      authButton.setSessionStatusCallback(new Session.StatusCallback() {

       @Override
       public void call(Session session, SessionState state, Exception exception) {

        if (session.isOpened()) {
                  Log.i(TAG,"Access Token"+ session.getAccessToken());
                  postToWall();
                  Request.executeMeRequestAsync(session,
                          new Request.GraphUserCallback() {
                              @Override
                              public void onCompleted(GraphUser user,Response response) {
                                  if (user != null) { 

                                   Log.i(TAG,"User ID "+ user.getId());
                                   Log.i(TAG,"Email "+ user.asMap().get("email"));

// lblEmail.setText(user.asMap()。get(“email”)。toString());

                                   String Email= (String) user.asMap().get("email");
                                   Toast.makeText(getApplicationContext(), Email, Toast.LENGTH_LONG).show();
                                   Intent intent = new Intent(getApplicationContext(), ShareCommentActivity.class);
                                   startActivity(intent);

                                  }
                              }
                          });
              }

       }
      });

这里是post to wall方法

@SuppressWarnings("deprecation")
    public void postToWall() {
        // post on user's wall.
        facebook.dialog(this, "feed", new DialogListener() {

            @Override
            public void onFacebookError(FacebookError e) {
            }

        @Override
        public void onError(DialogError e) {
        }

        @Override
        public void onComplete(Bundle values) {
        }

        @Override
        public void onCancel() {
        }
    });

提前致谢

0 个答案:

没有答案