static AccessToken createFromRefresh(AccessToken accesstoken, Bundle bundle) { if (accesstoken.source != AccessTokenSource.FACEBOOK_APPLICATION_WEB && accesstoken.source != AccessTokenSource.FACEBOOK_APPLICATION_NATIVE && accesstoken.source != AccessTokenSource.FACEBOOK_APPLICATION_SERVICE) { throw new FacebookException((new StringBuilder()).append("Invalid token source: ").append(accesstoken.source).toString()); } else { Date date = getBundleLongAsDate(bundle, "expires_in", new Date(0L)); bundle = bundle.getString("access_token"); return createNew(accesstoken.getPermissions(), accesstoken.getDeclinedPermissions(), bundle, date, accesstoken.source); } }
void forceExtendAccessToken(boolean paramBoolean) { AccessToken localAccessToken = getTokenInfo(); setTokenInfo(new AccessToken(localAccessToken.getToken(), new Date(), localAccessToken.getPermissions(), localAccessToken.getDeclinedPermissions(), AccessTokenSource.TEST_USER, new Date(0L))); setLastAttemptedTokenExtendDate(new Date(0L)); }
private void executeGraph(JSONArray args, CallbackContext callbackContext) throws JSONException { graphContext = callbackContext; PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); graphContext.sendPluginResult(pr); graphPath = args.getString(0); JSONArray arr = args.getJSONArray(1); final Set<String> permissions = new HashSet<String>(arr.length()); for (int i = 0; i < arr.length(); i++) { permissions.add(arr.getString(i)); } if (permissions.size() == 0) { makeGraphCall(); return; } boolean publishPermissions = false; boolean readPermissions = false; String declinedPermission = null; AccessToken accessToken = AccessToken.getCurrentAccessToken(); if (accessToken.getPermissions().containsAll(permissions)) { makeGraphCall(); return; } Set<String> declined = accessToken.getDeclinedPermissions(); // Figure out if we have all permissions for (String permission : permissions) { if (declined.contains(permission)) { declinedPermission = permission; break; } if (isPublishPermission(permission)) { publishPermissions = true; } else { readPermissions = true; } // Break if we have a mixed bag, as this is an error if (publishPermissions && readPermissions) { break; } } if (declinedPermission != null) { graphContext.error("This request needs declined permission: " + declinedPermission); } if (publishPermissions && readPermissions) { graphContext.error("Cannot ask for both read and publish permissions."); return; } cordova.setActivityResultCallback(this); LoginManager loginManager = LoginManager.getInstance(); // Check for write permissions, the default is read (empty) if (publishPermissions) { // Request new publish permissions loginManager.logInWithPublishPermissions(cordova.getActivity(), permissions); } else { // Request new read permissions loginManager.logInWithReadPermissions(cordova.getActivity(), permissions); } }