I spent the past few days looking thru almost every SO question about uploading an image to Facebook, and I still can't get it to work. This is what I've done so far:
1. Created an app on facebook and got the app id
2. dl'd the facebook sdk, along with the Example code they supply there (for the SampleUploadListener)
3. Added everything to the project, and used the code given in
Android - Upload photo to Facebook with Facebook Android SDK :
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile(photoToPost);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
This doens't seem to work. The code compiles and everything runs, but no facebook popup appears and nothing gets posted in Facebook - the app just runs right through it.
Any suggestions?
According to my knowledge you are right all the way, except for the "null" you have provided for the graph path in the request method.
YOu should provide a value for graph path. Eg:"me/photos". Try this,
mAsyncRunner.request("me/photos", params, "POST", new SampleUploadListener(), null);
replace null with "me/photos" and check. It should work fine if this is the only problem with your code.
All the best.
Related
I'm looking for (working) solution of sharing image issue.
I use Facebook SDK and everything is working fine in sharing except of putting image in parameters.
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmCanvas.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
parameters.putParcelable("picture",bmCanvas);
parameters.putString("name", "caption");
parameters.putString("description", "description");
parameters.putString("caption", "caption");
fb.dialog(CanvasActivity.this, "feed",parameters,new DialogListener(){ ....
i was trying with all of the options, i mean putting a picture parameter with uri, but also doesn't work.
The diallog with post on facebook is apearing but the image content is not loaded, and when i accept publishing the post, it's published but without photo.
Can anyone help me?
Or there is somebody who succesfully posted image from android internal or external storage to wall on facebook?
try using parameters.putByteArray("picture", bmCanvas);
instead of parameters.putParcelable("picture",bmCanvas);
I am posting a photo to FB using the new FB Android SDK 3.0. I am now looking for a way to set some more parameters than just the image itself and a simple text. I tried tons of different parameters, but non of them seem to do something.
What i would like to do is to add a link, an icon and, if somehow possible, a custom link item next to the Like and Comment links.
Here is an example of the icon and the custom link item from twitter:
And this is the code that I am currently using:
byte[] data = get binary image data;
Bundle postParams = new Bundle();
postParams.putString("name", "Image text");
postParams.putByteArray("picture", data);
// All these parameters do nothing...
postParams.putString("icon", "http://www.myimage.com/image.png");
postParams.putString("message", "XXX");
postParams.putString("caption", "Build great social apps and get more installs.");
postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
postParams.putString("link", "https://developers.facebook.com/android");
Request request = new Request(Session.getActiveSession(), "me/photos", postParams, HttpMethod.POST);
Response r = request.executeAndWait();
The post looks like this:
1. Adding the icon
You can manage icons from your app's dashboard: https://developers.facebook.com/apps/APP_ID/appdetails
2. Adding an action link
What you can a "custom link" is in fact an "action".
The "action" you've seen on the Twitter's post has been done using the actions array from the Post table:
A list of available actions on the post (including commenting, liking,
and an optional app-specified action)
So, your only choice if you really want to add this action near Like ยท Comment is to create a Post into the Feed and not a Photo.
Here is an a priori working code:
postParams.putString("message", "XXX");
postParams.putString("caption", "developers.facebook.com");
postParams.putString("description", "A tool to help you learn and browse the Facebook Graph API.");
postParams.putString("actions", "[{
'name':'Test a simple Graph API call!',
'link':'https://developers.facebook.com/tools/explorer?method=GET&path=me'
/* ^ This link must direct to the application's connect or canvas URL.
You'll get an error otherwise. */
}]"
);
postParams.putString("type", "photo");
postParams.putString("link", "https://developers.facebook.com/tools/explorer/");
postParams.putString("picture", "http://blog.programmableweb.com/wp-content/ishot-44.png");
Request request = new Request(Session.getActiveSession(), "me/feed", postParams, HttpMethod.POST);
3. Test in the Graph API Explorer
4. Timeline preview
How can I send the place params while uploading a photo from android to facebook.
Bundle params = new Bundle();
params.putByteArray("photo", byteArray);
params.putString("caption", "FbAPIs Sample App photo upload");
//params.putString("place", "Banglore");
//params.putString("location", "banglore");
Utility.mAsyncRunner.request("me/photos", params, "POST",
new PhotoUploadListener(), null);
Add the place to the params, much like you did the caption.
params.putString("place","someLocation");
You're almost there. Instead of using "Bangalore" for example, pass in the Facebook place ID.
Ex:
params.putString("place", "106377336067638");
For reference, see: https://developers.facebook.com/docs/reference/api/user/#photos
I am trying to post an image from my Resource folder onto facebook wall. everything is working perfectly. If i use a URL of an image, it gets posted on my facebook wall. What i want to know is how do i ost an image from my resource folder to facebook wall. here is a snippet of my code. any help will be greatly appreciated.
Bundle params = new Bundle();
Context ctx = null;
#SuppressWarnings("null")
Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(),R.drawable.bestbuy_deal);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitMapData = stream.toByteArray();
params.putString("name","ICE App");
params.putString("caption", "Bestbuy Deal for SONY Action Cam");
params.putString("description", "Checkout SONY ICE For exciting deals!!");
params.putString("link", "http://www.sony.com");
params.putByteArray("picture", bitMapData);
// params.putString("picture", "R.drawable.sony");
facebook.dialog(this, "me/feed",params, new DialogListener()
According to the Facebook API docs, the "picture" parameter must be a URL to the picture, not an array of bytes. I imagine this is because the facebook dialog is using a WebView to display the feed post, and the image must therefore be available on the web.
You could try using a local resource URI, but this may not work completely since the Facebook API will need to be smart enough to pull that data from the local URI and put it up on their own servers. I'd be keen to know if it works, though!
I have been searching for this all day and just when I find something, I find it is not what I am looking for. In short, I am upgrading my app to use the Facebook graph API for Android and the documentation is horrible. All I want is to upload a picture into the default album for the app. I have the following code:
Facebook f = new Facebook(APP_ID);
Bundle parameters = new Bundle();
parameters.putString("message", caption);
parameters.putByteArray("picture", data);
f.dialog(mContext, "publish.stream", parameters, this); //TODO: This is wrong
I think the publish.stream is what is the problem because the exception that I got when I did my "this doesn't have a prayer" test was a malformedURLException.
Can someone tell me if I am even on the right track?
Thanks,
Jake