OAuthException when trying to post to friends wall

I have a lot of trouble when you send a message to friends wall using api for Android 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}} 
+4
source share
2 answers

You probably recently created this Facebook app, which means that the changes in February 2013 are included.

February changes:

Removing the ability to post to friends through the graphical API

We will remove the ability to post to friends โ€™walls through the Graph API. In particular, messages against [user_id] / feed, where [user_id] are different from the session user, or stream.publish, where target_id is different from the session user, will fail. If you want to allow users to send messages according to their friends' schedules, call the feed dialog. Stories that include friends through the user, tagging tags or action tags will be displayed on the friends timeline (provided that the friend approves the tag). See this blog post for more information.

We will disable this feature starting in February, if you want to enable it (only temporarily until February), go to the application control panel> Settings> Advanced> Disable "February 2013 Breaking Changes"

I highly recommend not to do this, however, starting in February, this feature will cause your application to repeat the same error again.

+15
source

I have a solution that can help you, I use this for my code and its performance.

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 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 only work for one user, if you want to send it to multiple users, then you can use RequestsDialogBuilder instead of WebDialog.

+2
source

Source: https://habr.com/ru/post/953117/


All Articles