Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuthException when trying to Post to Friends Wall

Im having alot of trouble trying to post to a friends wall using the Facebook api in Android. This is what I have at the moment:

if (facebook.isSessionValid()) {
                        String response = facebook.request((userID == null) ? "me" : userID);

                        Bundle params = new Bundle();
                        params.putString("message", "put message here");
                        params.putString("link", "http://mylink.com");    
                        params.putString("caption", "{*actor*} just posted this!");
                        params.putString("description", "description of my link.  Click the link to find out more.");
                        params.putString("name", "Name of this link!");
                        params.putString("picture", "http://mysite.com/picture.jpg");

                        response = facebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");       

                        Log.d("Tests",response);
                        if (response == null || response.equals("") || 
                                response.equals("false")) {
                            Log.v("Error", "Blank response");
                        }
                    } else {
                        // no logged in, so relogin
                        Log.d("1234567890", "sessionNOTValid, relogin");

                    }
                }catch(Exception e){
                    e.printStackTrace();
                }

But this returns with this error:

12-11 21:34:06.604: D/FACEBOOK RESPONSE(14954): {"error":{"message":"(#200) Feed story publishing to other users is disabled for this application","type":"OAuthException","code":200}}
like image 830
Marche101 Avatar asked Dec 04 '22 01:12

Marche101


2 Answers

You probably created this Facebook application recently, which means the February 2013 breaking changes are enabled.

February's Breaking Changes include:

Removing ability to post to friends walls via Graph API

We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag). For more info, see this blog post.

We are disabling this feature starting in February, if you wish to enable it (only temporarily until February), go to your app dashboard > Settings > Advanced > Disable "February 2013 Breaking Changes"

I highly recommend against doing so, however, since starting February this functionality will cause your app to throw the same error again.

like image 102
Jesse Chen Avatar answered Dec 26 '22 06:12

Jesse Chen


I have the solution that might help you, I am using this for my code and its working fine..

private void publishFeedDialog(String friend_uid) {

    try{
            Session mCurrentSession = Session.getActiveSession();

            SessionTracker mSessionTracker = new SessionTracker(
                    getBaseContext(), new StatusCallback() {
                        public void call(Session session, SessionState state,
                                Exception exception) {
                        }
                    }, null, false);
            String applicationId = Utility
            .getMetadataApplicationId(getBaseContext());
            mCurrentSession = mSessionTracker.getSession();

            if (mCurrentSession == null
                    || mCurrentSession.getState().isClosed()) {
                mSessionTracker.setSession(null);
                Session session = new Session.Builder(getBaseContext())
                .setApplicationId(applicationId).build();
                Session.setActiveSession(session);
                mCurrentSession = session;
            }

            if (!mCurrentSession.isOpened()) {
                Session.OpenRequest openRequest = null;
                openRequest = new Session.OpenRequest(
                        NewFriendList.this);

                if (openRequest != null) {
                    openRequest
                    .setDefaultAudience(SessionDefaultAudience.FRIENDS);
                    openRequest.setPermissions(Arrays.asList("email", "publish_actions"));
                    openRequest
                    .setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);



                    mCurrentSession.openForPublish(openRequest);
                }
            }



            if (regobj != null && friend_uid != null ) {

                final Activity activity = this;
                Bundle params = new Bundle();
                //This is what you need to post to a friend's wall
                params.putString("from", "" + regobj.MyFBID);
                params.putString("to", friend_uid);
                //up to this
                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(this, mCurrentSession, 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(activity,
                                        "Posted story, id: "+postId,
                                        Toast.LENGTH_SHORT).show();
                                } else {
                                    // User clicked the Cancel button
                                    Toast.makeText(activity, 
                                        "Publish cancelled", 
                                        Toast.LENGTH_SHORT).show();
                                }
                            } else if (error instanceof FacebookOperationCanceledException) {
                                // User clicked the "x" button
                                Toast.makeText(activity, 
                                    "Publish cancelled", 
                                    Toast.LENGTH_SHORT).show();
                            } else {
                                // Generic, ex: network error
                                Toast.makeText(activity, 
                                    "Error posting story", 
                                    Toast.LENGTH_SHORT).show();
                            }
                        }



                    }).build();
                feedDialog.show();
            }
    }catch(Exception e)
    {
        Log.d("Error", ""+e.toString());
    }
}

This code will work for only one user, if you want to send it to multiple user then you can use RequestsDialogBuilder instead of WebDialog.

like image 25
ABHI Avatar answered Dec 26 '22 06:12

ABHI