在Facebook墙上发布sdk 3.5 android错误

时间:2014-01-03 09:55:31

标签: java android facebook-graph-api

我已经在facebook集成中登录并且在登录后我想在墙上发布一些消息但是我没有获得成功,因为我收到此错误

 **{Response:  responseCode: 200, graphObject: null, error: {HttpStatus: 200, errorCode: 3, errorType: null, errorMessage: Unknown method}, isFromCache:false}**  

我的代码如下

postbtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        try {



                            final Bundle params = new Bundle();

                            params.putString("message", "Test");
                            //params.putString("name", "American Virgin");
                            //params.putString("link", "http://bit.ly/12345");
                            //params.putString("description", "A Freshman College Girl on a scholarship from an ...");
                            //http://graph.facebook.com/100000431012652/picture?type=square
                            final Request postToWall = Request.newRestRequest(Session.getActiveSession(),  "me/feed", params, HttpMethod.POST);
                            postToWall.setCallback( new Request.Callback() 
                            {

                                @Override
                                public void onCompleted(Response response) 
                                {
                                    Log.i("onCompleted", response.toString());

                                }
                            });
                            Request.executeBatchAsync(postToWall);










                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            Log.i("onCompletedException", e.toString());
                        }


                    }
                });


            }

请建议我。 登录我使用以下代码

 Session.openActiveSession(this, true, new Session.StatusCallback() {

             // callback when session changes state
             @SuppressWarnings("deprecation")

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


               if (session.isOpened()) {
                  // Log.i("session.isOpened", "session.isOpened");
                   //session.requestNewReadPermissions(newPermissionsRequest);

                   // make request to the /me API
                 Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                   // callback after Graph API response with user object
                   @Override
                   public void onCompleted(GraphUser user, Response response) {

                       //session.requestNewReadPermissions(newPermissionsRequest);

                       //System.out.println("Response : "+response.toString()); 
                       Log.i("Response", response.toString());

                       //URL image_value = new URL("http://graph.facebook.com/"+id+"/picture?style=small" );


                     if (user != null) {

                      Log.i("USERName", ""+user.getName());
                      Log.i("Birthday", ""+user.getBirthday());
                      Log.i("LastName", ""+user.getLastName());
                      Log.i("FirstName", ""+user.getFirstName());
                      Log.i("getId", ""+user.getId());
                      Log.i("email", " "+user.getLink()+" email : ) "+user.asMap().get("email"));
                      Log.i("location", ""+user.asMap().get("location"));
                      Log.i("gender", ""+user.asMap().get("gender"));

                      saveusrname = ""+user.getName().trim();


                      imagstring = "http://graph.facebook.com/"+""+""+user.getId()+"/picture?type=square";

                      // imagstring = "http://graph.facebook.com/"+""+""+user.getId()+"/picture?type=large";
                      //type=square
                      Log.i("imagstring", imagstring);

                      finish();


                     /* String username = ""+user.getName();
                      String Birthday = ""+user.getBirthday();
                      String email = ""+user.asMap().get("email");
                      String location = ""+user.asMap().get("location");
                      String gender = ""+user.asMap().get("gender");*/


                      new SendfacebookValue().execute(response.toString(),saveusrname.toString(),imagstring);


                      /*Intent i =new Intent(FacebookLogin.this, ScreenNameActivity.class);
                      startActivity(i);*/

                       /* Intent i =new Intent(getApplicationContext(), MainActivity.class);
                        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(i);*/

                        //finish();

                     }
                   }
                 });



               }
             }
           });

1 个答案:

答案 0 :(得分:1)

我使用这种方法在Facebook墙上发布记录。我认为它会对你有所帮助,检查你的GraphObject

  private void postStatusUpdate() {
    Log.d("myLogs", "Test");
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
    } else {
        Session.openActiveSession(this, true, statusCallback);
        Log.d("myLogs", "Test 1");
        final String message = "massage to post";
        Request request = Request
                .newStatusUpdateRequest(Session.getActiveSession(), message, new Request.Callback() {
                    @Override
                    public void onCompleted(Response response) {
                        showPublishResult(message, response.getGraphObject(), response.getError());
                    }
                });
        request.executeAsync();
    }
}


private void showPublishResult(String message, GraphObject result, FacebookRequestError error) {
    String title = null;
    String alertMessage = null;
    if (error == null) {
        title = "Success";

        alertMessage = "All is good";
    } else {
        title = "Error";
        alertMessage = error.getErrorMessage();
    }

    new AlertDialog.Builder(this)
            .setTitle(title)
            .setMessage(alertMessage)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            })
            .show();
}