here is the facebook sample
Bundle params = new Bundle();
params.putString("source", "{image-data}");
/* make the API call */
new Request(
session,
"/me/photos",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
what is {image-data}
I tried use byte[].toString, file.toString, path of file. not work.
so how to upload photo with this api?
facebook doc is wrong.
change
params.putString("source", "{image-data}");
to
params.putByteArray("source", "{image-data}");
If you want to post a photo, use one of the Request.newUploadPhotoRequest methods, it will set everything up for you.
See https://developers.facebook.com/docs/reference/android/current/class/Request/#newUploadPhotoRequest
Related
I am using Facebook android SDK (V4) to post a message on Facebook using "me/feed" graph API.
Bundle params = new Bundle();
params.putString("message", message);
new GraphRequest(
token,
"me/feed",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//Handle response
}
}
).executeAsync();
This is working fine.
Now I want to add feeling/Activity in my post.
I have search on Google but haven't found any solution on that.
Does anybody know of a way?
Thanks in advance.
Hi guys I am trying to upload a photo to a page on Facebook. This is the page i am trying to post the photo https://www.facebook.com/manegedagen/.
I have been using the following code :
public static void postImageOnWall(Bitmap pBitmap) {
Bundle bundle =new Bundle();
bundle.putString("method", "photos.upload");
bundle.putString("picture","http://www.demos.com/LangGuage/medal_1.png");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/2091172661108128/feed",
null,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.e("", "");
}
}
).executeAsync();
}
But i am getting an error message: OAuthException: errorMessage: Invalid parameters. I would really appreciate if i can get any guide or help.
Try with parameters not as null
see the selected answer from this reference:
https://stackoverflow.com/a/29770773/6011938
On android I'm using Facebook SDK 4.0. I want to get all photos of a user logged in via Facebook login.
I have this URL
https://graph.facebook.com/FACEBOOK_ID/albums?access_token=TOKEN
How do I parse and generate images to be viewed in a ListView ?
set Bundle for extra parameters like crate a bundle for required parameters ex:
Bundle parameters = new Bundle();
parameters.putString("fields", "id, picture");
Then set it to GraphRequest.
you have to used below code to get all photos of user.
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{user-id}/photos",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
I am new to android development. I am trying to post photo from an android app to user's facebook album. I added following code after I logged in the user with permissions "user_friends"
new GraphRequest(
MainFragment.mAccessToken.getCurrentAccessToken(),
"/me/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
// This is my code for user login at app start
post = (Button)view.findViewById(R.id.button1);
mLoginManager = LoginManager.getInstance();
mLoginManager.registerCallback(mCallbackManager, mCallback);
mLoginManager.logInWithReadPermissions(this, Arrays.asList("user_friends")); //user_friends // publish_actions
Please guide me
I did a mistake .. Firstly, my question was incomplete .. I have found the issue .. Following seems to be working.
MainFragment.mLoginManager.logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
Bundle params = new Bundle();
params.putString("url", "http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg");
/* make the API call /
new GraphRequest(
MainFragment.mAccessToken.getCurrentAccessToken(),
"/me/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/ handle the result */
Log.d("MainFragment:", "onCompleted mAccessToken = " + MainFragment.mAccessToken.getCurrentAccessToken());
}
}
).executeAsync();
I'm currently able to post to a public page wall using:
JSONObject json = new JSONObject();
json.put("message", "I'm on your wall");
Request req = Request.newPostRequest(getSession(), "PowerCardSoftware/feed", GraphObject.Factory.create(json), new Callback() {
#Override
public void onCompleted(Response response) {
if(response.getError() != null)
Log.e("FRAGACTIVITY", response.getError().toString());
Toast.makeText(getBaseContext(), "I hacked your facebook!", Toast.LENGTH_SHORT).show();
}
});
Request.executeBatchAsync(req);
I would like to post a picture the user takes onto the public wall as well. I've tried using a Bundle instead of a JSONObject and using each of these lines:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
postPhoto.compress(CompressFormat.JPEG, 100, baos);
params.putByteArray("picture", baos.toByteArray());
params.putByteArray("source", baos.toByteArray());
They both give me an error like this - errorMessage: (#100) picture URL is not properly formatted
Anyone know how to post a photo onto someone else's facebook wall without using deprecated functions/Objects in the facebook sdk?
This is my code to upload a photo stored locally on the phone:
Request request6 = Request.newUploadPhotoRequest(
session,
((BitmapDrawable) getResources().getDrawable(
R.drawable.picture)).getBitmap(), callback6);
RequestAsyncTask task6 = new RequestAsyncTask(request6);
task6.execute();
This is to upload on your own wall. Reason why there is no option to choose another recipient is due to the breaking changes in February that will disable posting to other people's wall.
See my earlier answer.
EDIT:
what is the best way to upload a photo that will show up on a place's wall with a photo and message?
Can you try this and see if this works?
Bundle parameters = new Bundle();
parameters.putParcelable("picture", YOUR_BITMAP_HERE);
parameters.putString("message", "my message for the page");
return new Request(session, "PowerCardSoftware/feed", parameters, HttpMethod.POST, callback);
Can I add a message using newUploadPhotoRequest()?
No, to add a message with your photo, you won't be using newUploadPhotoRequest. If you dig into the source, its just a wrapper of a Request, so do the same as the method, but add an additional parameter, message, with the message you want, and execute it. I haven't personally verified it but it should work. Let me know if it doesn't.
This is my solution.
I referenced Jesse Chen's answer and made some modifications.
Bitmap image = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "demo.jpg");
Bundle parameters = new Bundle();
parameters.putParcelable("source", image);
parameters.putString("message", "my message for the page");
Request request = new Request(Session.getActiveSession(), "me/photos", parameters, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
showPublishResult(mainActivity.getString(R.string.photo_post), response.getGraphObject(), response.getError());
}
});
request.executeAsync();
You can check facebookSDK project /tests folders and search keywords newPostRequest.
the sample code is as below
GraphObject statusUpdate = GraphObject.Factory.create();
String message = "message";
statusUpdate.setProperty("message", message);
statusUpdate.setProperty("link", "http://stackoverflow.com/questions/14129546/android-post-picture-to-facebook-public-page-wall#");
Request request = Request.newPostRequest(Session.getActiveSession(), "me/feed", statusUpdate, new Callback() {
#Override
public void onCompleted(Response response) {
}
});
request.executeAsync();