display image from resource folder on facebook wall in android - android

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!

Related

Share Image and Text to Facebook on android

What is the correct way to share an image and text to Facebook in android?
e.g. picture with pre-populated text.
I realise that this is not possible from the native Android share intent as described here. As it can only take an image or a link not both.
Also I have tried using the facebook-sdk-3.14 with:
FacebookDialog.ShareDialogBuilder
but I now realise this is for sharing links only.
I have also tried with:
createShareDialogBuilderForPhoto()
but this is for sharing images only.
Is there something I am missing in the sdk? I am guessing it is not possible from FacebookDialog?
Will I need to go the route of creating my own app in facebook and my own open graph action? Ideally I am looking to not have a login button.
I have also seen similar questions but most are about the share intent or if it is the sdk it at least a year out of date and the solution is some thing similar to this:
Bundle parameters = new Bundle();
parameters.putString("message", category_item_name_desc.getText().toString());
parameters.putString("picture", categoryItemsModel.getImageUrl());
parameters.putString("caption", txtDescription_desc.getText().toString());
facebook.request("/me/feed", parameters, "POST");
Tried it through the Feed Dialog (WebDialog) but im getting a "error (#324) requires upload file", Any help would be great.
You can share your image on facebook, Twitter, and Gmail:
Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType(“image/jpeg”);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, “Title”, null);
Uri imageUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, “Select”));
Was able to do this my self with the current Facebook SDK (3.14.1 at the time) with no login and I made it into a share intent for adding to the chooser list.
I have a demo project at https://github.com/b099l3/FacebookImageShareIntent only dependency is the facebook sdk and it is contained in one activity.
Please take a look a look on my library: https://github.com/antonkrasov/AndroidSocialNetworks
With help of it, posting is really easy:
mSocialNetworkManager.getFacebookSocialNetwork().postMessage(String message)
mSocialNetworkManager.getFacebookSocialNetwork().postPhoto(File path...)

Share image from Android app to facebook , with Facebook SDK

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);

upload a bitmap to facebook from android app

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.

Create photo album in facebook using android and Graph api

We have a problem creating photo album in facebook using android and graph API. We already have been able to upload photos to facebook using Graph API. We are using following for uploading a photo to facebook.
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putString("title", uploadFile.getName());
params.putString("privacy", "{'value':'EVERYONE'}");
facebook.request("https://api.facebook.com/restserver.php?method=photos.upload",params,"POST");
Please let us know if anybody aware of. We have searched a
I have found the working solution for the above problem.
Bundle params = new Bundle();
params.putString("name", albumName);
String response = mFacebook.request("https://graph.facebook.com/me/albums",params,"POST");
String albumId=Util.parseJson(response).getString("id");
Above code will help create a new photo album with the albumName and return the album id generated by facebook.

Send a picture to Facebook using Graph API on Android

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

Categories

Resources