本文整理汇总了Java中com.facebook.AccessToken.setCurrentAccessToken方法的典型用法代码示例。如果您正苦于以下问题:Java AccessToken.setCurrentAccessToken方法的具体用法?Java AccessToken.setCurrentAccessToken怎么用?Java AccessToken.setCurrentAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.AccessToken
的用法示例。
在下文中一共展示了AccessToken.setCurrentAccessToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finishLogin
import com.facebook.AccessToken; //导入方法依赖的package包/类
private void finishLogin(
AccessToken newToken,
LoginClient.Request origRequest,
FacebookException exception,
boolean isCanceled,
FacebookCallback<LoginResult> callback) {
if (newToken != null) {
AccessToken.setCurrentAccessToken(newToken);
Profile.fetchProfileForCurrentAccessToken();
}
if (callback != null) {
LoginResult loginResult = newToken != null
? computeLoginResult(origRequest, newToken)
: null;
// If there are no granted permissions, the operation is treated as cancel.
if (isCanceled
|| (loginResult != null
&& loginResult.getRecentlyGrantedPermissions().size() == 0)) {
callback.onCancel();
} else if (exception != null) {
callback.onError(exception);
} else if (newToken != null) {
callback.onSuccess(loginResult);
}
}
}
示例2: onMethodCall
import com.facebook.AccessToken; //导入方法依赖的package包/类
@Override
public void onMethodCall(final MethodCall call, final Result result) {
Map<String, String> params = call.arguments();
boolean loggedIn = getAccessToken() != null;
if (loggedIn) {
AccessToken.setCurrentAccessToken(getAccessToken());
}
Log.i(getClass().getSimpleName(), "onMethodCall: " + (loggedIn ? "true" : "false"));
switch (call.method) {
case "logout":
saveAccessToken(null);
AccessToken.setCurrentAccessToken(null);
result.success(new HashMap<String, Object>());
break;
case "login":
loginWithCallback(FacebookHelper.loginResultCallback(result, loginResult -> {
Log.d("Success", "Login");
saveAccessToken(loginResult.getAccessToken());
AccessToken accessToken = loginResult.getAccessToken();
Map<String, Object> data = new HashMap<>();
data.put("accessToken", accessToken.getToken());
data.put("acceptedPermissions", TextUtils.join(",", accessToken.getPermissions().toArray()));
data.put("deniedPermissions", TextUtils.join(",", accessToken.getDeclinedPermissions().toArray()));
data.put("userId", accessToken.getUserId());
data.put("expiresIn", accessToken.getExpires().getTime());
result.success(data);
}));
break;
case "graph/me":
if (!loggedIn) {
loginWithCallback(FacebookHelper.loginResultCallback(result, loginResult -> {
saveAccessToken(loginResult.getAccessToken());
queryMe(result);
}));
} else {
queryMe(result);
}
break;
default:
result.notImplemented();
break;
}
}
示例3: logOut
import com.facebook.AccessToken; //导入方法依赖的package包/类
/**
* Logs out the user.
*/
public void logOut() {
AccessToken.setCurrentAccessToken(null);
Profile.setCurrentProfile(null);
}