Facebook的SDK为Android 3.0:UnsupportedOperationException异常 [英] Facebook SDK for Android 3.0: UnsupportedOperationException
问题描述
01-29 21:06:00.601: ERROR/AndroidRuntime(582): FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:2144)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at android.view.View$1.onClick(View.java:2139)
... 11 more
Caused by: java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that is not currently open.
at com.facebook.Session.requestNewPermissions(Session.java:977)
at com.facebook.Session.requestNewPublishPermissions(Session.java:501)
at ***.MainActivity.postToFacebook(MainActivity.java:105)
... 14 more
唯一的例外是抛出行
The exception is thrown in line
session.requestNewPublishPermissions(newPermissionsRequest);
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
Toast.makeText(getActivity().getApplicationContext(),
"Not enough permissions",
Toast.LENGTH_SHORT).show();
return;
}
这是什么意思的异常,以及如何解决它?
What does this exception mean and how to fix it?
推荐答案
德米特罗,按我的评论,我已经把一对夫妇的文章,充分说明打开Facebook的会话,并要求额外的权限:的这里和的此处。希望你和其他人发现它有利于节省时间开始使用的SDK! :)
Dmytro, as per my comment, I've put together a couple of articles which fully explain opening a Facebook session and requesting additional permissions: here and here. Hope you and others find it beneficial and save time getting started with the SDK! :)
编辑:您收到此异常的原因是因为你不能
要求在非公开会议上新的权限。你需要打开你的
请求新的权限或进行其他Facebook的API之前会话
要求。我已经把挂在上面的文章指南
这保证了Facebook的API请求(如发布到用户的饲料
等)不进行,直到用户会话已打开,并且
用户拥有所需的权限。
The reason you are getting this exception is because you can't request new permissions on a non-open session. You need to open your session before requesting new permissions or making other Facebook API requests. I've put together a guide in the articles linked to above which ensure a Facebook API request (such as posting to a user's feed and so forth) is not made until the the user's session is open and the user has the required permissions.
这篇关于Facebook的SDK为Android 3.0:UnsupportedOperationException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!