gpt4 book ai didi

Android 用相机捕捉图像并与 Facebook sdk 分享

转载 作者:太空宇宙 更新时间:2023-11-03 10:54:16 25 4
gpt4 key购买 nike

我正在尝试使用 Facebook SDK 中的 Facebook 对话框上传图像(由相机拍摄)。但它在 facebook 登录后崩溃了。我找不到问题。

这是我的代码

protected void postStatus() {
byte[] data = null;
try {
ContentResolver cr = getContentResolver();
InputStream fis = cr.openInputStream(MyCarDealActivity.imageUri);
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bundle parameters = new Bundle();
parameters.putString("method", "photos.upload");
parameters.putByteArray("picture", data);
parameters.putString("caption", "Hello");
facebook.dialog(FacebookScreen.this, "me/photos", parameters,
new DialogListener() {

@Override
public void onCancel() {

}

@Override
public void onComplete(Bundle values) {
Toast.makeText(FacebookScreen.this, "Published",
Toast.LENGTH_LONG).show();
finish();
}

@Override
public void onError(DialogError e) {
Toast.makeText(FacebookScreen.this,
"Error :" + e.getLocalizedMessage(),
Toast.LENGTH_LONG).show();
finish();
}

@Override
public void onFacebookError(FacebookError e) {
Toast.makeText(FacebookScreen.this,
"Error :" + e.getLocalizedMessage(),
Toast.LENGTH_LONG).show();
finish();
}

});
}

这是错误日志

11-27 13:40:33.434: ERROR/AndroidRuntime(376): java.lang.NullPointerException
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at java.net.URLEncoder.encode(URLEncoder.java:53)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.facebook.android.Util.encodeUrl(Util.java:85)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.facebook.android.Facebook.dialog(Facebook.java:609)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.kchaddock.mycardeal.FacebookScreen.postStatus(FacebookScreen.java:67)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.kchaddock.mycardeal.FacebookScreen$1.onComplete(FacebookScreen.java:34)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.facebook.android.Facebook$1.onComplete(Facebook.java:304)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.facebook.android.FbDialog$FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:134)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:216)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:323)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at android.os.Looper.loop(Looper.java:123)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at java.lang.reflect.Method.invokeNative(Native Method)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at java.lang.reflect.Method.invoke(Method.java:507)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-27 13:40:33.434: ERROR/AndroidRuntime(376): at dalvik.system.NativeStart.main(Native Method)

提前致谢

最佳答案

尝试使用以下内容代替 facebook.dialog:

facebook.request("me/feed", params, "POST");

关于Android 用相机捕捉图像并与 Facebook sdk 分享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8284301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com