0

我有这个代码..这里唯一的工作是登录...我想实现发布到墙上或提要对话框..我在这里有墙上帖子的代码,但它仍然不起作用..任何帮助将不胜感激...我按照此链接登录

[链接] http://www.kpbird.com/2013/03/android-login-using-facebook-sdk-30.html

我正在尝试在此登录中嵌入帖子状态..

public class FacebookActivity extends FragmentActivity {

    private Button publishButton;


     private String TAG = "FacebookActivity";
     private TextView lblEmail;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.facebook_activity);
      lblEmail = (TextView) findViewById(R.id.lblEmail);

      LoginButton authButton = (LoginButton) findViewById(R.id.authButton);

      authButton.setOnErrorListener(new OnErrorListener(){

        @Override
        public void onError(FacebookException error) {
            Log.i(TAG, "Error " + error.getMessage());
        }
            // TODO Auto-generated method stub



      });


      // set permission list, Don't forget to add email
      authButton.setReadPermissions(Arrays.asList("basic_info","email"));
      // 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());
                  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());
                                  }
                              }
                          });

                  publishButton.setVisibility(View.VISIBLE);
              }
        else if (state.isClosed()) {
            publishButton.setVisibility(View.INVISIBLE);
        }
       }
      });


      publishButton = (Button) findViewById(R.id.publishButton);
      publishButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              publishFeedDialog();        
          }
      });

     }

     private void publishFeedDialog() {
            Bundle params = new Bundle();
            params.putString("name", "Facebook SDK for Android");
            params.putString("caption", "Build great social apps and get more installs.");
            params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
            params.putString("link", "https://developers.facebook.com/android");
            params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

            WebDialog feedDialog = (
                new WebDialog.FeedDialogBuilder(getActivity(),
                    Session.getActiveSession(),
                    params))
                .setOnCompleteListener(new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values,
                        FacebookException error) {
                        if (error == null) {
                            // When the story is posted, echo the success
                            // and the post Id.
                            final String postId = values.getString("post_id");
                            if (postId != null) {
                                Toast.makeText(getActivity(),
                                    "Posted story, id: "+postId,
                                    Toast.LENGTH_SHORT).show();
                            } else {
                                // User clicked the Cancel button
                                Toast.makeText(getActivity().getApplicationContext(), 
                                    "Publish cancelled", 
                                    Toast.LENGTH_SHORT).show();
                            }
                        } else if (error instanceof FacebookOperationCanceledException) {
                            // User clicked the "x" button
                            Toast.makeText(getActivity().getApplicationContext(), 
                                "Publish cancelled", 
                                Toast.LENGTH_SHORT).show();
                        } else {
                            // Generic, ex: network error
                            Toast.makeText(getActivity().getApplicationContext(), 
                                "Error posting story", 
                                Toast.LENGTH_SHORT).show();
                        }
                    }

                })
                .build();
            feedDialog.show();

        }





     protected ContextWrapper getActivity() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }


    }
4

0 回答 0