Android 应用程序未在 Facebook 上发布图片
您好,我正在使用教程在 Facebook 上发布图像,但它没有发布。请指导我做错了什么。我在手机上安装了 facebook.apk。我已经完全按照 Facebook 开发者指南中的描述进行操作。
这是错误......
public class DummyActivity extends Activity {
Facebook facebook = new Facebook("xxxxxxxxxxxx");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
facebook.authorize(this, new DialogListener() {
public void onComplete(Bundle values) {
byte[] data = null;
Bitmap bi = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
}
public void onFacebookError(FacebookError error) {}
public void onError(DialogError e) {}
public void onCancel() {}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
这是另一个类,
public class SampleUploadListener implements RequestListener {
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
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 onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
Hi I am using a tutorial to post image on facebook but its not posting. Please guide what i am doing wrong. I have facebook.apk installed on mobile. I have done extactly what is described on Facebook developer guiide.
Here is the error....
public class DummyActivity extends Activity {
Facebook facebook = new Facebook("xxxxxxxxxxxx");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
facebook.authorize(this, new DialogListener() {
public void onComplete(Bundle values) {
byte[] data = null;
Bitmap bi = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
}
public void onFacebookError(FacebookError error) {}
public void onError(DialogError e) {}
public void onCancel() {}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
Here is another class,
public class SampleUploadListener implements RequestListener {
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
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 onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您使用了错误的参数!
查看photos.upload 文档
You are using wrong parametes!
Check the documentation of photos.upload
像这样更改您的代码,
尝试将参数的键值更改为“照片”而不是“图片”,并在请求方法中为 GRaphApi 提供 null,这肯定是错误的。
Change your code like this,
Try changing the keyvalue for param as "photo" instead of "picture" and in the request method you are providing null for GRaphApi which is certainly wrong.
试试这个 FB
它可能对你有帮助。
Try this one FB
it may helps you.
好的,我成功登录了,并发布了这是正确的回复吗...
OK, i managed to log in, and posted is it the right response...