繁体   English   中英

使用SDK 3.5 Android错误在Facebook墙上发布信息

[英]Posting on facebook wall with sdk 3.5 android error

我已经完成了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();

                     }
                   }
                 });



               }
             }
           });

我使用这种方法在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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM