本文介绍了为什么我的code不工作从Android中上传照片到Facebook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我参加办法整合Facebook的-SDK成功。现在我要分享的照片到Facebook。要做到这一点我用这code:
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);
和另外code是:
@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
}
}
现在,我不知道为什么我不能够让上传的照片在Facebook上?
Now, I dont know why i am not able to get upload photo on the facebook?
推荐答案
根据你想要做什么,你需要给一个目标(第一空),以这条线code:
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);
您需要正确的权限才能做到这一点:至少publish_stream
You will need the correct permissions to do this: at least publish_stream.
请参阅文档
这篇关于为什么我的code不工作从Android中上传照片到Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!