it might be duplicate question so sorry please consider it as my problem .
i am facing problem image posting on facebook wall from android application but image not display on wall it is visible inside Photos-----> your photos section but i want this images should display on user time line or wall please help me .
my code is
Bundle params = new Bundle();
// Inflate Edit text for Facebook Message
params.putString("method", "photos.upload");
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("app_id", mAPP_ID); // I've tried with/without this,
// same result
params.putString("message", message);
Bitmap b = BitmapFactory
.decodeResource(getResources(), R.drawable.test);
Log.i("Bitmap Image is here", "Bitmap" + b);
if (b != null) {
Log.i("Bitmap", "value");
} else {
Log.i("Bitmap", "null");
}
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
if (data != null) {
params.putByteArray("picture", data);
Log.i("final", "value" + message);
params.putString("access_token", facebook.getAccessToken());
try {
facebook.request("me");
facebook.request("me/photos", params, "POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I faced similar issue some time ago: FB combines all photo uploads into single post on your timeline when you upload more than one photo during a short period of time. Also, it looks like you do not provide custom photo message and privacy settings, so your code can be significantly simplified (I assume you are using the latest FB android sdk, have the session opened, and already requested publish_stream permission):
Bitmap image2Upload = ...;
Request uploadRequest = Request.newUploadPhotoRequest(Session.getActiveSession(), image2Upload, null);
String photoId = null;
String postId = null;
try {
Response uploadResponse = Request.executeAndWait(uploadRequest);
JSONObject json = uploadResponse.getGraphObject().getInnerJSONObject();
photoId = json.getString("id");
postId = json.optString("post_id");
} catch(Throwable t) {
Log.e(TAG, "Photo upload request failed!", t);
}
Related
I have tried many code to send the image on facebook wall but it is not working.
I am using this code
Bitmap bitmap = BitmapFactory.decodeResource(shareDialogContext.getResources(),R.drawable.splash);
byte[] byetArray = convertBitmapToByteArray(shareDialogContext,bitmap);
params.putByteArray("picture",byetArray);
objFacebook.request(profileID + "me/photos", params, "POST");
public byte[] convertBitmapToByteArray(Context context, Bitmap bitmap) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(bitmap.getWidth() *
bitmap.getHeight());
bitmap.compress(CompressFormat.PNG, 100, buffer);
return buffer.toByteArray();
}
Please suggest any useful code.
Doesn't hackbook example do exactly what you want?
Bundle params = new Bundle();
try {
params.putByteArray("photo",
Utility.scaleImage(getApplicationContext(), photoUri));
} catch (IOException e) {
e.printStackTrace();
}
params.putString("caption", "FbAPIs Sample App photo upload");
Utility.mAsyncRunner.request("me/photos", params, "POST",
new PhotoUploadListener(), null);
This may help you:
Bundle params = new Bundle();
try
{
params.putByteArray("photo",Utility.scaleImage(getApplicationContext(), photoUri));
}
catch (IOException e)
{
e.printStackTrace();
}
params.putString("caption", "Through My Android Application");
Utility.mAsyncRunner.request("me/photos", params, "POST",new PhotoUploadListener(), null);
Possible duplicate : Android - Upload photo to Facebook with Facebook Android SDK
private void postToWall(String msg) {
Bundle parameters = new Bundle();
// parameters.putString("method", "stream.publish");
JSONObject attachment = new JSONObject();
try {
byte[] data = null;
Bitmap bi = BitmapFactory.decodeResource(getResources(),
R.drawable.bluerib);
// Bitmap bi =
// BitmapFactory.decodeFile("http://demos.com/LangGuage/medal_1.png");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 30, baos);
data = baos.toByteArray();
// Bundle params = new Bundle();
// params.putByteArray("picture", data);
attachment.put("type", "image");
// attachment.put("picture", data);
attachment.put("name", "LangGuage");
attachment.put("message", msg);
attachment.put("src", "http://demos.com/LangGuage/medal_1.png");
attachment.put("href", "http://www.abc.com");
// attachment.put("href",
// "http://hwsdemos.com/LangGuage/medal_1.png");
parameters.putString(Facebook.TOKEN, facebook.getAccessToken());
parameters.putString("attachment", attachment.toString());
String response = facebook.request("me/photos", parameters, "POST");
System.out.println("----responce" + response);
if (response.contains("Duplicate status message")) {
progressHandler.sendEmptyMessage(1);
resp = 1;
} else if (response == null || response.equals("")
|| response.equals("false") || response.contains("error")) {
Log.d("error", "error response");
} else {
progressHandler.sendEmptyMessage(0);
resp = 0;
}
} catch (Exception e) {
Log.e(TAG, "Posting fail");
e.printStackTrace();
// finish();
}
}
My app is supporting single sign-in for facebook. I don't want to use dialogs.
Whenever I try to post an image and message together in a attachment I catch:
{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}
See the docs for a photos graph POST request here https://developers.facebook.com/docs/reference/api/user/#photos
Your image data should go into the "source" field, and the only other available fields are "message", "place' and "no_story". The "src", "name", "href" are not valid fields.
I am making a photo gallery app in which I try to load images from asset folder. I'm successful in doing this.
Now I want to share the image(single not multiple) via email, facebook and twitter.
This is where my problem starts.
I'm able to post a plain message via my app but I'm unable to post my image or attach my image with it.
I don't know how to do this. I tried many tutorials but to no help.
You have to upload image first somewhere on the internet, so the Facebook can download it.
here you go it works for me:
final Session session = Session.getActiveSession();
if (session != null){
// check publish permissions here
// if there is no permission request it and return;
//else if there is permission
logMessage("Has permission go on");
final Bundle postParams = new Bundle();
if(File("yourImagePath").exists())
{
byte[] data = null;
File screenShotFile = new File("yourImagePath");
logMessage("getting screenShot here");
FileInputStream fis = new FileInputStream(screenShotFile);
Bitmap bitmap = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
postParams.putByteArray("picture", data);
logMessage("added pic as byte array to params");
}
postParams.putString("name", "Post name");
postParams.putString("caption", "caption");
postParams.putString("description", "desc");
postParams.putString("link", "http://www....");
final Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response)
{
FacebookRequestError error;
try {
error = response.getError();
if (error != null)
{
makeToast(error.getErrorMessage());
logMessage(error.getErrorMessage());
}
else
{
// no errors so delete image here
if(screenShotFile != null)
{
screenShotFile.delete();
logMessage("deleted");
screenShotFile = null;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logMessage(response.toString());
}
};
Request request = new Request(session, "me/photos", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
logMessage("made feed request check");
}
I have integrated Facebook to my Android application.Now I want to fetch the information like specific posts which are only made by my application.
How can I do this ? Please help.
Edited.
In my application a user can post message to his wall.What I want is if user's friends also uses same application and post messages through the application.
So I want to retrieve all those messages of user from his wall which are made through the application(By him and his friends).
OK I have solved problem my own.
I have used fql for retrieving information I needed.
This is how I have used fql.
For retrieving messages & other data from my wall (only those which are made through my application).
private String getWallInfo()
{
try
{
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", "SELECT post_id, actor_id, app_id, message FROM stream where source_id = me() and app_id = "
+ ConnectData.APP_ID);
String response = facebook.request(params);
Log.i(TAG, "response = " + response);
return response;
} catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
For retrieving messages & other data from my friends wall (only those which are made through my application).
private String getFriendsWallInfo()
{
try
{
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query",
"SELECT post_id, actor_id, app_id, message FROM stream WHERE source_id IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND app_id="
+ ConnectData.APP_ID);
String response = facebook.request(params);
Log.i(TAG, "response = " + response);
return response;
} catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
Here is the code for uploading picture into my facebook :
Bundle parameters = new Bundle();
parameters.putString("message", msg);
byte[] imgData = getImage("http://bandungraos.in/wp-content/resto/1/gallery/kepiting1.jpg");
parameters.putByteArray("picture", imgData);
if (imgData != null) {
try {
String response = facebook.request("me/photos", parameters,"POST");
System.out.println(response);
} catch (IOException e) {
e.printStackTrace();
}
}
.....
private byte[] getImage(String url) {
try {
URL imgUrl = new URL(url);
HttpURLConnection cn = (HttpURLConnection) imgUrl.openConnection();
cn.setDoInput(true);
cn.connect();
int length = cn.getContentLength();
byte[] imgData = new byte[length];
InputStream is = cn.getInputStream();
is.read(imgData);
return imgData;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
I checked that either access token or imgData is not null
There is no error but I can't find the image in my facebook.
Thanks in advance
According to the User object documentation about the Photos connection the image parameter is named "source" and not "picture", have you tried:
Bundle parameters = new Bundle();
parameters.putString("message", msg);
parameters.putByteArray("source", getImage("..."));
I had the same problem and i used this code `
private void upload_FB(Bitmap photo2) {
// TODO Auto-generated method stub
Calendar c = Calendar.getInstance();
String name = c.getTime().toString();
AsyncFacebookRunner fruner = new AsyncFacebookRunner(facebook);
Log.d("adr", mCurrentPhotoPath);
if(photo2!=null && mCurrentPhotoPath!=null){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
photo2.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] bMapArray = baos.toByteArray();
Bundle params = new Bundle();
params.putByteArray("photo",bMapArray);
params.putString("caption", name);
fruner.request("me/photos",params,"POST",new PhotoUploadListener(),null);
}else
Toast.makeText(ctx, "ERROR", Toast.LENGTH_LONG).show();
}
don't forget to add premision photo_upload
`