我想通过facebook SDK发布图片和文字标题。
我指的是此处发布的解决方案。
Android post picture to Facebook wall
但是,我收到以下错误。
FATAL EXCEPTION: main
java.lang.NullPointerException
at java.net.URLDecoder.decode(URLDecoder.java:104)
at java.net.URLDecoder.decode(URLDecoder.java:48)
at com.facebook.android.Util.openUrl(Util.java:173)
at com.facebook.android.Facebook.request(Facebook.java:751)
at com.xxx.yyy.gui.share.ShareDialogFactory.shareThroughFacebook(ShareDialogFactory.java:170)
我已针对之前发布的解决方案验证了我的代码。
private static void shareThroughFacebook(final Context context, final File file, final int heartbeatForShare) {
final Facebook facebook = new Facebook("285243934881501");
// Login.
facebook.authorize((Activity)context, new String[] { "publish_stream" }, new DialogListener() {
@Override
public void onComplete(Bundle values) {
android.util.Log.i("CHEOK", "onComplete");
}
@Override
public void onFacebookError(FacebookError error) {
android.util.Log.i("CHEOK", "onFacebookError");
}
@Override
public void onError(DialogError e) {
android.util.Log.i("CHEOK", "onError");
}
@Override
public void onCancel() {
android.util.Log.i("CHEOK", "onCancel");
}
});
android.util.Log.i("CHEOK", "STEP 1");
final byte[] data = JPEG2ByteArray(file);
final Bundle bundle = new Bundle();
bundle.putString(Facebook.TOKEN, facebook.getAccessToken());
android.util.Log.i("CHEOK", "data length is " + data.length);
bundle.putByteArray("picture", data);
bundle.putString("message", "this-is-message");
bundle.putString("caption", "this-is-caption");
// I can reach till here!
android.util.Log.i("CHEOK", "STEP 2");
try {
// NPE happens right here!!!
facebook.request("me/photos", bundle, "POST");
} catch (FileNotFoundException e1) {
android.util.Log.i("CHEOK", "FileNotFoundException");
e1.printStackTrace();
} catch (MalformedURLException e1) {
android.util.Log.i("CHEOK", "MalformedURLException");
e1.printStackTrace();
} catch (IOException e1) {
android.util.Log.i("CHEOK", "IOException");
e1.printStackTrace();
}
android.util.Log.i("CHEOK", "STEP 3");
}
我可以确认我的字节数组是非零长度。我在authorize
期间没有收到任何回调,也不确定这是否是正确的行为。请注意,代码shareThroughFacebook
是从Dialog
。
我错过了其他任何步骤吗?