我试图从我的Android应用程序共享一个opengraph对象。这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
Log.d(TAG, "SDK inicijalizirano");
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
accessToken = loginResult.getAccessToken();
Log.d("Success", accessToken.getToken());
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "books.book")
.putString("og:title", "A Game of Thrones")
.putString("og:description", "In the frozen S")
.putString("books:isbn", "0-553-57340-3")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.reads")
.putObject("book", object)
.putBoolean("fb:explicitly_shared", true)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("book")
.setAction(action)
.build();
ShareLinkContent linkcontent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://developers.facebook.com"))
.build();
ShareApi.share( content, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.d(TAG, "Story posted! " + result);
}
@Override
public void onCancel() {
Log.d(TAG, "canceled");
}
@Override
public void onError(FacebookException e) {
Log.d(TAG, "error posting: " + e.getMessage());
}
});
}
@Override
public void onCancel() {
Log.d(TAG, "Canceled");
}
@Override
public void onError(FacebookException exception) {
Log.d(TAG, "Not OK");
if (exception instanceof FacebookAuthorizationException) {
if (AccessToken.getCurrentAccessToken() != null) {
LoginManager.getInstance().logOut();
}
}
}
});
setContentView(R.layout.activity_check_in);
shareOnFacebookBox=(CheckBox) findViewById(R.id.share_on_facebook_checkbox);
shareOnFacebookBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(shareOnFacebookBox.isChecked()){
Log.d(TAG, "chekirano");
if(AccessToken.getCurrentAccessToken()!=null){
LoginManager.getInstance().logOut();
}
LoginManager.getInstance().logInWithPublishPermissions(ActivityCheckIn.this, PERMISSIONS);
}else{
System.out.println("Un-Checked");
}
}
});
当我尝试ShareApi.share(linkcontent,新的FacebookCallback ......);有用。 当我尝试ShareApi.share(内容,新面孔......)时,它附带
09-07 10:11:04.940 22452-22452/? D/Success﹕ CAAPP8XKZCZCzEBADo2jAMmrZBsKhn9zOYaC4VZAYtbXttjgazmSal8yxPOUOHgJioiMfT5ZCkBeDWzWBJluX6LSXaRW8jBnsPtrD3tfYcKa1rrlHSubPO4si0riMCORl0okCpLxlRehLOXKMJWZBCOHLqt4YbfjuZCoRRDh595B2ZCFYMuzWs6CpJhcknSDCnK1451ixtAYIyWeOP6mjn00WEpZCobuviZAvNadI6JEOjZCRwZDZD09-07 10:11:05.600 22452-22452/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity {com.teamwe.go/com.teamwe.go.activities.ActivityCheckIn}: java.util.ConcurrentModificationException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3660)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3710)
at android.app.ActivityThread.access$1100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:792)
at java.util.HashMap$KeyIterator.next(HashMap.java:819)
at com.facebook.internal.CollectionMapper.iterate(CollectionMapper.java:60)
at com.facebook.share.ShareApi.stageCollectionValues(ShareApi.java:456)
at com.facebook.share.ShareApi.stageOpenGraphAction(ShareApi.java:484)
at com.facebook.share.ShareApi.shareOpenGraphContent(ShareApi.java:221)
at com.facebook.share.ShareApi.share(ShareApi.java:165)
at com.facebook.share.ShareApi.share(ShareApi.java:73)
at com.teamwe.go.activities.ActivityCheckIn$1.onSuccess(ActivityCheckIn.java:141)
at com.teamwe.go.activities.ActivityCheckIn$1.onSuccess(ActivityCheckIn.java:117)
at com.facebook.login.LoginManager.finishLogin(LoginManager.java:509)
at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:192)
at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:140)
at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:82)
at com.teamwe.go.activities.ActivityCheckIn.onActivityResult(ActivityCheckIn.java:349)
at android.app.Activity.dispatchActivityResult(Activity.java:5275)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3656)
这是我的
protected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);}
请注意:我成功登录后,会在日志中打印accessToken,而不是应用程序崩溃。
提前谢谢你。