0

在我的應用程序中,我嘗試使用特定位置進行登錄。facebook checkin權限錯誤

但每次我有這樣的錯誤

{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) Requires extended permission: publish_actions}, isFromCache:false} 

我做肯定把publish_actions權限在我的權限列表。

我在這裏做錯了什麼?爲什麼我每次都有這樣的錯誤?

這裏是我的代碼:

private Session.StatusCallback statusCallback = new SessionStatusCallback(); 
    private class SessionStatusCallback implements Session.StatusCallback { 
     @Override 
     public void call(Session session, SessionState state, Exception exception) { 
      if (session.isOpened()){ 
       checkIn(session); 
       PrefsCacheManager.getInstance().putInCashe("accessToken" , session.getAccessToken()); 
      } 
     } 
    } 

    private UiLifecycleHelper uiHelper; 
    private LocationManager locationManager; 
    private Location lastKnownLocation; 
    private UiLifecycleHelper lifecycleHelper; 
    private Location pickPlaceForLocationWhenSessionOpened = null; 
    private static final int PLACE_ACTIVITY = 1; 
    private String mPlaceId; 
    private static final Location LOCATION = new Location("") {{}}; 

    private Session.StatusCallback callback = new Session.StatusCallback() { 
     @Override 
     public void call(Session session, SessionState state, 
         Exception exception) { 
     } 
    }; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     uiHelper = new UiLifecycleHelper(this, callback); 
     uiHelper.onCreate(savedInstanceState); 
     lifecycleHelper = new UiLifecycleHelper(this, new Session.StatusCallback() { 
      @Override 
      public void call(Session session, SessionState state, Exception exception) { 
       onSessionStateChanged(session, state, exception); 
      } 
     }); 
     lifecycleHelper.onCreate(savedInstanceState); 
     ensureOpenSession(); 
     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     init(); 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 
     mTracker.activityStart(this); 
    } 

    @Override 
    public void onStop() { 
     super.onStop(); 
     mTracker.activityStop(this); 
    } 

    private boolean ensureOpenSession() { 
     if (Session.getActiveSession() == null || 
       !Session.getActiveSession().isOpened()) { 
      Session.openActiveSession(this, true, new Session.StatusCallback() { 
       @Override 
       public void call(Session session, SessionState state, Exception exception) { 
        onSessionStateChanged(session, state, exception); 
       } 
      }); 
      return false; 
     } 
     return true; 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() { 
      @Override 
      public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { 
       Toast.makeText(FacebookCheckIn.this, getString(R.string.fb_share_failed), Toast.LENGTH_LONG).show(); 
      } 

      @Override 
      public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { 
      } 
     }); 
     lifecycleHelper.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == PLACE_ACTIVITY && resultCode == Activity.RESULT_OK){ 
      displaySelectedPlace(resultCode); 
     } else if (requestCode == PLACE_ACTIVITY && resultCode == Activity.RESULT_CANCELED){ 
      finish(); 
     } 
    } 

    private void displaySelectedPlace(int resultCode) { 
     String results = ""; 
     SmartBonusApplication application = (SmartBonusApplication) getApplication(); 

     GraphPlace selection = application.getSelectedPlace(); 
     if (selection != null) { 
      GraphLocation location = selection.getLocation(); 
      mPlaceId = selection.getId(); 
      checkFacebookSession(); 

     } 
    } 

    private void setLocation() { 
     try { 
      LOCATION.setLatitude(mBrench.getLat()); 
      LOCATION.setLongitude(mBrench.getLng()); 
      startPickPlaceActivity(LOCATION); 
     } catch (Exception ex) { 
      onError(ex); 
     } 
    } 
    private void onError(Exception exception) { 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Error").setMessage(exception.getMessage()).setPositiveButton("OK", null); 
     builder.show(); 
    } 

    private void checkFacebookSession() { 
     final String[] PERMISSION_ARRAY_READ = {"publish_actions" , "user_checkins"}; 
     final List<String> permissionList = Arrays.asList(PERMISSION_ARRAY_READ); 
     new Session.NewPermissionsRequest(FacebookCheckIn.this, permissionList); 
     Session session = Session.getActiveSession(); 
     if (session != null){ 
      if (!session.isOpened() && !session.isClosed()) { 
       session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); 
      }else { 
       Session.openActiveSession(this, true, statusCallback); 
      } 
     } else { 
      Session.openActiveSession(this, true, statusCallback); 
     } 
    } 

    private void checkIn(final Session pSession) { 
     Bundle params = new Bundle(); 
     if (pSession.getAccessToken() != null) { 
      params.putString("place", String.valueOf(mPlaceId)); 
      params.putString("message", mBrench.getCompany() + " " + mBrench.getAddress()); 
      params.putString("coordinates", "{\"longitude\":" + mBrench.getLng() + ",\"latitude\":" + mBrench.getLat() + "}"); 
      Request.Callback callback6 = new Request.Callback() { 
       public void onCompleted(Response response) { 
        checkInSuccess(); 
       } 
      }; 
      Request request6 = new Request(pSession, "me/checkins", params, HttpMethod.POST, callback6); 
      RequestAsyncTask task6 = new RequestAsyncTask(request6); 
      task6.execute(); 
     } 
    } 

    private void checkInSuccess() { 
     Intent intent = new Intent(FacebookCheckIn.this, CheckinSuccessActivity.class); 
     intent.putExtra("branche", mBrench); 
     intent.putExtra("type", VKONTAKTE); 
     startActivity(intent); 
     finish(); 
     overridePendingTransition(0, 0); 
    } 

    @Override 
    public void onBackPressed() { 
     super.onBackPressed(); 
     finish(); 
     overridePendingTransition(0, 0); 
    } 

    private void init() { 
     mTracker = EasyTracker.getInstance(this); 
     mBrench = getIntent().getParcelableExtra("branche"); 
     setLocation(); 
    } 

    private void onSessionStateChanged(Session session, SessionState state, Exception exception) { 
     if (pickPlaceForLocationWhenSessionOpened != null && state.isOpened()) { 
      Location location = pickPlaceForLocationWhenSessionOpened; 
      pickPlaceForLocationWhenSessionOpened = null; 
      startPickPlaceActivity(location); 
     } 
    } 

    private void startPickPlaceActivity(Location location) { 
     if (ensureOpenSession()) { 
      SmartBonusApplication application = (SmartBonusApplication) getApplication(); 
      application.setSelectedPlace(null); 
      Intent intent = new Intent(this, PickPlaceActivity.class); 
      PickPlaceActivity.populateParameters(intent, location, null); 
      startActivityForResult(intent, PLACE_ACTIVITY); 
     } else { 
      pickPlaceForLocationWhenSessionOpened = location; 
     } 
    } 
} 
+0

您是否稍後在代碼中添加了權限'publish_actions'?此外,雖然登錄,你看到擴展權限框說*「這個應用程序想代表你發佈」*? –

+0

我沒有看到任何框。我添加了publish_actions權限,當我想要簽入信息時 – pmb

回答

0

您必須後來添加的權限。並且由於該會話已經創建,因此不會要求獲得 publish_action權限。

所以,通過註銷Facebook來銷燬會話,然後重新登錄;或從 settings中刪除應用程序,然後嘗試。這樣,它會要求發佈許可,並且您將能夠成功發佈!


編輯:

出版與/簽入,現在已經過時。檢查 - /{user-id}/checkins

您必須立即使用Open Graph來發布具有位置的故事。

+0

你的意思是我必須通過用戶id/checkins來更改我/ checkins? – pmb

+0

不是。 '/ me/checkins'和'/ userid/checkins'和相同的東西。我說你現在不能使用這個檢查來發布檢查。這已被禁止。您必須使用開放圖形故事來發布位置。查看開發者網站的教程 –