本文整理汇总了Java中com.facebook.AccessToken类的典型用法代码示例。如果您正苦于以下问题:Java AccessToken类的具体用法?Java AccessToken怎么用?Java AccessToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessToken类属于com.facebook包,在下文中一共展示了AccessToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleFacebookAccessToken
import com.facebook.AccessToken; //导入依赖的package包/类
private void handleFacebookAccessToken(AccessToken token) {
Log.d(TAG, "handleFacebookAccessToken:" + token);
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
示例2: handleFacebookAccessToken
import com.facebook.AccessToken; //导入依赖的package包/类
private void handleFacebookAccessToken(AccessToken token) {
LogUtil.logDebug(TAG, "handleFacebookAccessToken:" + token);
showProgress();
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
LogUtil.logDebug(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
handleAuthError(task);
}
}
});
}
示例3: newUploadStagingResourceWithImageRequest
import com.facebook.AccessToken; //导入依赖的package包/类
/**
* Creates a new Request configured to upload an image to create a staging resource. Staging
* resources allow you to post binary data such as images, in preparation for a post of an Open
* Graph object or action which references the image. The URI returned when uploading a staging
* resource may be passed as the image property for an Open Graph object or action.
*
* @param accessToken the access token to use, or null
* @param file the file containing the image to upload
* @param callback a callback that will be called when the request is completed to handle
* success or error conditions
* @return a Request that is ready to execute
* @throws FileNotFoundException
*/
public static GraphRequest newUploadStagingResourceWithImageRequest(
AccessToken accessToken,
File file,
Callback callback
) throws FileNotFoundException {
ParcelFileDescriptor descriptor =
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
GraphRequest.ParcelableResourceWithMimeType<ParcelFileDescriptor> resourceWithMimeType =
new GraphRequest.ParcelableResourceWithMimeType<>(descriptor, "image/png");
Bundle parameters = new Bundle(1);
parameters.putParcelable(STAGING_PARAM, resourceWithMimeType);
return new GraphRequest(
accessToken,
MY_STAGING_RESOURCES,
parameters,
HttpMethod.POST,
callback);
}
示例4: registerAccessTokenTracker
import com.facebook.AccessToken; //导入依赖的package包/类
private static void registerAccessTokenTracker() {
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
if (oldAccessToken == null) {
// If we never had an access token, then there would be no pending uploads.
return;
}
if (currentAccessToken == null ||
!Utility.areObjectsEqual(
currentAccessToken.getUserId(),
oldAccessToken.getUserId())) {
// Cancel any pending uploads since the user changed.
cancelAllRequests();
}
}
};
}
示例5: UploadContext
import com.facebook.AccessToken; //导入依赖的package包/类
private UploadContext(
ShareVideoContent videoContent,
String graphNode,
FacebookCallback<Sharer.Result> callback) {
// Store off the access token right away so that under no circumstances will we
// end up with different tokens between phases. We will rely on the access token tracker
// to cancel pending uploads.
this.accessToken = AccessToken.getCurrentAccessToken();
this.videoUri = videoContent.getVideo().getLocalUrl();
this.title = videoContent.getContentTitle();
this.description = videoContent.getContentDescription();
this.ref = videoContent.getRef();
this.graphNode = graphNode;
this.callback = callback;
this.params = videoContent.getVideo().getParameters();
}
示例6: canShare
import com.facebook.AccessToken; //导入依赖的package包/类
/**
* Returns true if the content can be shared. Warns if the access token is missing the
* publish_actions permission. Doesn't fail when this permission is missing, because the app
* could have been granted that permission in another installation.
*
* @return true if the content can be shared.
*/
public boolean canShare() {
if (this.getShareContent() == null) {
return false;
}
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken == null) {
return false;
}
final Set<String> permissions = accessToken.getPermissions();
if (permissions == null || !permissions.contains("publish_actions")) {
Log.w(TAG, "The publish_actions permissions are missing, the share will fail unless" +
" this app was authorized to publish in another installation.");
}
return true;
}
示例7: shareLinkContent
import com.facebook.AccessToken; //导入依赖的package包/类
private void shareLinkContent(final ShareLinkContent linkContent,
final FacebookCallback<Sharer.Result> callback) {
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject data = response.getJSONObject();
final String postId = (data == null ? null : data.optString("id"));
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
};
final Bundle parameters = new Bundle();
this.addCommonParameters(parameters, linkContent);
parameters.putString("message", this.getMessage());
parameters.putString("link", Utility.getUriString(linkContent.getContentUrl()));
parameters.putString("picture", Utility.getUriString(linkContent.getImageUrl()));
parameters.putString("name", linkContent.getContentTitle());
parameters.putString("description", linkContent.getContentDescription());
parameters.putString("ref", linkContent.getRef());
new GraphRequest(
AccessToken.getCurrentAccessToken(),
getGraphPath("feed"),
parameters,
HttpMethod.POST,
requestCallback).executeAsync();
}
示例8: createAccessTokenFromNativeLogin
import com.facebook.AccessToken; //导入依赖的package包/类
static AccessToken createAccessTokenFromNativeLogin(
Bundle bundle,
AccessTokenSource source,
String applicationId) {
Date expires = Utility.getBundleLongAsDate(
bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);
if (Utility.isNullOrEmpty(token)) {
return null;
}
String userId = bundle.getString(NativeProtocol.EXTRA_USER_ID);
return new AccessToken(
token,
applicationId,
userId,
permissions,
null,
source,
expires,
new Date());
}
示例9: authorize
import com.facebook.AccessToken; //导入依赖的package包/类
void authorize(Request request) {
if (request == null) {
return;
}
if (pendingRequest != null) {
throw new FacebookException("Attempted to authorize while a request is pending.");
}
if (AccessToken.getCurrentAccessToken() != null && !checkInternetPermission()) {
// We're going to need INTERNET permission later and don't have it, so fail early.
return;
}
pendingRequest = request;
handlersToTry = getHandlersToTry(request);
tryNextHandler();
}
示例10: computeLoginResult
import com.facebook.AccessToken; //导入依赖的package包/类
static LoginResult computeLoginResult(
final LoginClient.Request request,
final AccessToken newToken
) {
Set<String> requestedPermissions = request.getPermissions();
Set<String> grantedPermissions = new HashSet<String>(newToken.getPermissions());
// If it's a reauth, subset the granted permissions to just the requested permissions
// so we don't report implicit permissions like user_profile as recently granted.
if (request.isRerequest()) {
grantedPermissions.retainAll(requestedPermissions);
}
Set<String> deniedPermissions = new HashSet<String>(requestedPermissions);
deniedPermissions.removeAll(grantedPermissions);
return new LoginResult(newToken, grantedPermissions, deniedPermissions);
}
示例11: getPermissions
import com.facebook.AccessToken; //导入依赖的package包/类
public void getPermissions() {
String uri = "me/permissions/";
new GraphRequest(AccessToken.getCurrentAccessToken(),
uri, null, HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
JSONArray data = response.getJSONObject().optJSONArray("data");
mUserPermissions.clear();
for (int i = 0; i < data.length(); i++) {
JSONObject dd = data.optJSONObject(i);
if (dd.optString("status").equals("granted")) {
mUserPermissions
.add(dd.optString("permission"));
}
}
}
}
).executeAsync();
}
示例12: revokePermission
import com.facebook.AccessToken; //导入依赖的package包/类
public void revokePermission(final String permission) {
AccessToken token = AccessToken.getCurrentAccessToken();
String uri = "me/permissions/" + permission;
GraphRequest graphRequest = GraphRequest.newDeleteObjectRequest(
token, uri, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
if (error == null) {
Utils.d("FB:Revoke:Response:" + response.toString());
getPermissions();
}
}
});
graphRequest.executeAsync();
}
示例13: revokeAccess
import com.facebook.AccessToken; //导入依赖的package包/类
/** GraphRequest **/
public void revokeAccess() {
mAuth.signOut();
AccessToken token = AccessToken.getCurrentAccessToken();
GraphRequest graphRequest = GraphRequest.newDeleteObjectRequest(
token, "me/permissions", new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
if (error == null) {
Utils.d("FB:Delete:Access" + response.toString());
}
}
});
graphRequest.executeAsync();
}
示例14: handleAccessToken
import com.facebook.AccessToken; //导入依赖的package包/类
public void handleAccessToken(AccessToken token) {
Utils.d("FB:Handle:AccessToken: " + token.getToken());
// showProgressDialog();
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Utils.d("FB:signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Utils.w("FB:signInWithCredential" +
task.getException().toString());
}
// hideProgressDialog();
}
});
}
示例15: successLogin
import com.facebook.AccessToken; //导入依赖的package包/类
protected void successLogin (FirebaseUser user) {
Utils.d("FB:Login:Success");
isFacebookConnected = true;
accessToken = AccessToken.getCurrentAccessToken();
try {
currentFBUser.put("name", user.getDisplayName());
currentFBUser.put("email_id", user.getEmail());
currentFBUser.put("photo_uri", user.getPhotoUrl());
currentFBUser.put("token", accessToken.getToken().toString());
} catch (JSONException e) { Utils.d("FB:JSON:Error:" + e.toString()); }
getPermissions();
// call Script
Utils.callScriptFunc("Auth", "FacebookLogin", "true");
}