36011

Android : How to post Photo/Video on friend wall with android sdk?

Question:

I tried this example : <a href="https://stackoverflow.com/questions/6688957/android-how-to-post-picture-to-friends-wall-with-facebook-android-sdk" rel="nofollow">Android how to post picture to friend's wall with facebook android sdk</a>

but not work. here is my code :

String response = Utility.mFacebook.request((userID == null) ? "me" : userID); final Bundle params = new Bundle(); params.putString("message", "test"); params.putString("caption", "test"); params.putString("picture", "http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"); response = Utility.mFacebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");

Any sample code that able post video/photo on friend wall?

Answer1:

This is the method i use to post a picture to a wall, it posts a pic from a URL but you can change it to put a byte[] for the pic instead. The message appears above the picture and the caption appears to the right of the picture.

protected void postPicToWall(String userID, String msg, String caption, String picURL){ try { if (isSession()) { String response = mFacebook.request((userID == null) ? "me" : userID); Bundle params = new Bundle(); params.putString("message", msg); params.putString("caption", caption); params.putString("picture", picURL); response = mFacebook.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(TAG, "sessionNOTValid, relogin"); mFacebook.authorize(this, PERMS, new LoginDialogListener()); } }catch(Exception e){ e.printStackTrace(); } }

To post a byte[] rather than a url to a pic then replace the line

params.putString("picture", picURL); with

params.putByteArray("picture", getIntent().getExtras().getByteArray("data"));

where data is your array.

Recommend

  • WorkManager Data.Builder does not support Parcelable
  • Uncaught TypeError: ref.putString is not a function
  • Android Studio - Can't Read preferenceSettings
  • Set Facebook graph Request to always return English results
  • Wrap C++ function using Boost Reflect or another C++ reflection library
  • android Navigation Bar hiding and persantage of usable screen overlap
  • Declaring variable dynamically in VB.net
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • HTTP/2 streams vs HTTP/1.1 connections
  • azure media services - The request body is too large and exceeds the maximum permissible limit
  • Rails Find when some params will be blank
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Play WS (2.2.1): post/put large request
  • Get data from AJAX - How to
  • Syntax for setting draggablecursor property in google maps api
  • NHibernate Validation Localization with S#arp Architecture
  • Initializer list vs. initialization method
  • How can I send an e-mail from a vbs script
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • Spring security and special characters
  • Optimizing database types to compact database (SQLite)
  • Accessing IRQ description array within a module and displaying action names
  • Cross-Platform Protobuf Serialization
  • JSON with duplicate key names losing information when parsed
  • Trying to switch camera back to front but getting exception
  • Do I've to free mysql result after storing it?
  • Jquery - Jquery Wysiwyg return html as a string
  • Python - Map / Reduce - How do I read JSON specific field in using DISCO count words example
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • GridView Sorting works once only
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • Getting Messege Twice Using IMvxMessenger
  • Turn off referential integrity in Derby? is it possible?
  • Can't mass-assign protected attributes when import data from csv file
  • JaxB to read class hierarchy
  • Programmatically clearing map cache