Reputation: 23606
I have integrated the Facebook-sdk successfully in to my appplication. Now i am going to share a photo to Facebook. To do that I am using this code:
facebook.authorize(DrawingActivity.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() {
@Override
public void onComplete(Bundle values) {}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
byte[] data = null; Bitmap bi = BitmapFactory.decodeFile(APP_FILE_PATH + "/myAwesomeDrawing.png");
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);
and another code is:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
public class SampleUploadListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
try {
// process the response here: (executed in background thread)
Log.d("Facebook-Example", "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String src = json.getString("src");
// then post the processed result back to the UI thread
// if we do not do this, an runtime exception will be generated
// e.g. "CalledFromWrongThreadException: Only the original
// thread that created a view hierarchy can touch its views."
} catch (JSONException e) {
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e) {
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
}
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
Now, I dont know why i am not able to get upload photo on the facebook?
Upvotes: 0
Views: 990
Reputation: 10938
Depending on what you want to do, you need to give a target (first null) to this line of code:
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
For example, if you're trying to make a post on the current users wall, it should look like:
mAsyncRunner.request("me/posts", params, "POST", new SampleUploadListener(), null);
You will need the correct permissions to do this: at least publish_stream.
See docs
Upvotes: 1