您好我正在使用教程在Facebook上发布图片但不发布。请指导我做错了什么。我在手机上安装了facebook.apk。我已经彻底完成了Facebook开发人员guiide所描述的内容。
这是错误....
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
}
答案 0 :(得分:0)
您使用了错误的参数!检查documentation of photos.upload
答案 1 :(得分:0)
像这样更改你的代码,
Bundle params = new Bundle();
try {
Bitmap bMap = BitmapFactory.decodeFile(config.downloaded_image_path);
Log.i("Path",config.downloaded_image_path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bMap.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
params.putByteArray("photo", b);
} catch (Exception e) {
e.printStackTrace();
}
params.putString("caption", config.facebook_comment);
Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
尝试将param的keyvalue更改为“photo”而不是“picture”,并且在请求方法中,您为GRaphApi提供null,这当然是错误的。
答案 2 :(得分:0)
试试这个FB
它可能对你有所帮助。
答案 3 :(得分:0)
好的,我设法登录,发布是正确的回复......
02-13 14:48:55.949: D/Facebook-Example(2814): Response: {"pid":"100002384000781_493454","aid":"100002384000781_53368","owner":100002384000781,"src":"http:\/\/photos-h.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_s.jpg","src_big":"http:\/\/a8.sphotos.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_n.jpg","src_small":"http:\/\/photos-h.ak.fbcdn.net\/hphotos-ak-ash4\/400189_233648050057993_100002384000781_493454_803419378_t.jpg","link":"http:\/\/www.facebook.com\/photo.php?fbid=233648050057993&set=a.233615786727886.53368.100002384000781&type=1","caption":"","created":1329124670,"object_id":233648050057993}