Facebook SDK 3.8:未返回权限publish_actions

我正在通过facebook( https://developers.facebook.com/docs/android/share )关注facebook的android分享教程。 该应用程序运行良好,我可以loginFacebook的点击演示共享button。 所以这是我的应用程序的过程:

  1. 用facebooklogin
  2. facebook会话对象被更新,以下权限被保存在会话对象中: user_likes, user_friends, user_status, basic_info
  3. 现在,我想分享一些东西。 因此用户点击一个共享button,并发出一个名为publish_actions的额外权限的请求

以下代码执行此请求:

 public class MainActivity extends Activity { private Button shareButton; private UiLifecycleHelper uiHelper; private static final List<String> PERMISSIONS = Arrays.asList("publish_actions"); private static final String PENDING_PUBLISH_KEY = "pendingPublishReauthorization"; private boolean pendingPublishReauthorization = false; ... private void publishStory() { Session session = Session.getActiveSession(); if( session != null) { List<String> permissions = session.getPermissions(); if(!isSubsetOf(PERMISSIONS, permissions)) { pendingPublishReauthorization = true; Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS); //Request the new permission here. The answer is processed in onSessionStateChange() method session.requestNewPublishPermissions(newPermissionsRequest); return; } ... private void onSessionStateChange(Session session, SessionState state, Exception exception) { //since the session is already open we enter this if branch if (state.isOpened()) { shareButton.setVisibility(View.VISIBLE); //The result of state.equals(SessionState.OPENED_TOKEN_UPDATED) is false which indicates that the session object has not been updated (as far as I understand the fb api) Log.e(TAG, "state.equals(SessionState.OPENED_TOKEN_UPDATED) = " + state.equals(SessionState.OPENED_TOKEN_UPDATED)); //Output all the current permission the session has (publish_actions is not included here) List<String> permissions = session.getPermissions(); Iterator<String> it = permissions.iterator(); Log.e(TAG, "Content of list:"); while(it.hasNext()) Log.e(TAG, "permission = " + it.next()); //Since the OPENED_TOKEN_UPDATED has not been updated nothing further happens here if (pendingPublishReauthorization && state.equals(SessionState.OPENED_TOKEN_UPDATED)) { pendingPublishReauthorization = false; publishStory(); } } else if (state.isClosed()) { shareButton.setVisibility(View.INVISIBLE); } } 

所以,虽然这似乎是正确的,但是还是有一些剩余的错误。 publish_actions权限没有被授予,但我不明白为什么。 只有现有的权限仍然是publish_actions

进一步的评论:我读过一些问题,说应该出现一个额外的popup窗口,要求用户授予权限。 然而,这不是在我的情况发生。 也许这是问题? 如果是这样,我需要做些什么来获得popup窗口?

更新:我还额外尝试从github下面的要点: https ://gist.github.com/vishalpawale/5556996由于完全相同的原因,此示例代码失败。 它没有得到任何publish_action权限。 似乎是Facebook SDK中的一个实际的错误?

Solutions Collecting From Web of "Facebook SDK 3.8:未返回权限publish_actions"

对于发布权限,您应该在应用设置中发送请求并发送审核请参阅https://developers.facebook.com/docs/apps/review/

如果您在3月30日以后使用Facebook sdk 3.14.x +则facebook更改了应用程序testing和提交stream程。 发布有关权限的答案。 检查这个链接

我们在这里有同样的问题。

尝试使用:

 Session.getActiveSession().refreshPermissions(); 

这将刷新可用的权限列表

 List<String> permissions = session.getPermissions(); 

它只能与Facebook注册开发者用户或通过Facebook App Dashboard注册的testing用户合作。

这对我们有效。

它只返回读取权限,而不是写入权限。 尝试下面的代码片段

  final Bundle permBundle = new Bundle(); permBundle.putCharSequence("permission", "publish_actions"); GraphRequest request = new GraphRequest( AccessToken.getCurrentAccessToken(), "/me/permissions", permBundle, HttpMethod.GET, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse graphResponse) { Log.d(TAG, "response2: " + graphResponse.getJSONObject()); try { JSONArray permList = (JSONArray) graphResponse.getJSONObject().get("data"); if(permList.length() == 0){ // no data for perms, hence asking permission askForFBPublishPerm(); }else{ JSONObject permData = (JSONObject) permList.get(0); String permVal = (String) permData.get("status"); if(permVal.equals("granted")){ postToFB(); }else{ askForFBPublishPerm(); } } } catch (JSONException e) { Log.d(TAG, "exception while parsing fb check perm data" + e.toString()); } } } ); request.executeAsync();