Java Code Examples for com.facebook.AccessToken#getCurrentAccessToken()

The following examples show how to use com.facebook.AccessToken#getCurrentAccessToken() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
public void initUserProfile(final IOperationFinishWithDataCallback profileFetched, boolean isForceUpdate) {
    if (userProfile != null && !isForceUpdate) {
        profileFetched.operationFinished(userProfile);
    } else if (!isLogedIn()) {
        userProfile = new UserProfile();
        profileFetched.operationFinished(userProfile);
    } else {
        if (AccessToken.getCurrentAccessToken() != null) {
            fetchFacebookUserData(profileFetched);
        } else if (Twitter.getSessionManager().getActiveSession() != null) {
            fetchTwitterUserData(profileFetched);
        } else if (VKSdk.isLoggedIn()) {
            fetchVkUserData(profileFetched);
        }
    }
}
 
Example 2
Source File: VideoUploader.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: ShareApi.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
public void logout() {
    if (AccessToken.getCurrentAccessToken() != null) {
        LoginManager.getInstance().logOut();
        Logger.printInfo(LOG_TAG, "Loged out from facebook");
    }
    if (Twitter.getSessionManager().getActiveSession() != null) {
        Twitter.getSessionManager().clearActiveSession();
        Twitter.logOut();
        Logger.printInfo(LOG_TAG, "Loged out from twitter");
    }
    if (VKSdk.isLoggedIn()) {
        VKSdk.logout();
        Logger.printInfo(LOG_TAG, "Loged out from vk");
    }
    Prefs.remove(SyncMaster.GLOBAL_TOKEN);
    userProfile = new UserProfile();
}
 
Example 5
Source File: LoginClient.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 6
Source File: LoginClient.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
void validateSameFbidAndFinish(Result pendingResult) {
    if (pendingResult.token == null) {
        throw new FacebookException("Can't validate without a token");
    }

    AccessToken previousToken = AccessToken.getCurrentAccessToken();
    AccessToken newToken = pendingResult.token;

    try {
        Result result = null;
        if (previousToken != null && newToken != null &&
                previousToken.getUserId().equals(newToken.getUserId())) {
            result = Result.createTokenResult(pendingRequest, pendingResult.token);
        } else {
            result = Result
                    .createErrorResult(
                            pendingRequest,
                            "User logged in as different Facebook user.",
                            null);
        }
        complete(result);
    } catch (Exception ex) {
        complete(Result.createErrorResult(
                pendingRequest,
                "Caught exception",
                ex.getMessage()));
    }
}
 
Example 7
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
public String getToken() {
    if (Prefs.getString(SyncMaster.GLOBAL_TOKEN, null) != null) {
        return Prefs.getString(SyncMaster.GLOBAL_TOKEN, null);
    } else if (AccessToken.getCurrentAccessToken() != null)
        return AccessToken.getCurrentAccessToken().getToken();
    else if (Twitter.getSessionManager().getActiveSession() != null) {
        TwitterSession session = Twitter.getSessionManager().getActiveSession();
        TwitterAuthToken authToken = session.getAuthToken();
        return authToken.token;
    } else
        return VKAccessToken.currentToken().accessToken;
}
 
Example 8
Source File: FacebookHelper.java    From AndroidBlueprints with Apache License 2.0 5 votes vote down vote up
private void initAccessTokenTracker() {
    mAccessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            // Set the access token using
            // currentAccessToken when it's loaded or set.
            // If the access token is available already assign it.
            mFacebookAccessToken = AccessToken.getCurrentAccessToken();
            //                Toast.makeText(mActivity, "Facebook current Access Token changed", Toast.LENGTH_SHORT)
            //                        .show();
        }
    };
}
 
Example 9
Source File: FacebookNetwork.java    From EasyLogin with MIT License 5 votes vote down vote up
@Override
public com.maksim88.easylogin.AccessToken getAccessToken() {
    if (com.facebook.AccessToken.getCurrentAccessToken() != null && accessToken == null) {
        AccessToken facebookToken = AccessToken.getCurrentAccessToken();
        accessToken = new com.maksim88.easylogin.AccessToken.Builder(facebookToken.getToken()).userId(facebookToken.getUserId()).build();
    }
    return accessToken;
}
 
Example 10
Source File: LoginWithFacebookSDKActivity.java    From Android-SDK with MIT License 5 votes vote down vote up
private void logoutFromFacebook()
{
	if (!isLoggedInFacebook)
		return;

	if (AccessToken.getCurrentAccessToken() != null)
		LoginManager.getInstance().logOut();

	isLoggedInFacebook = false;
	fbAccessToken = null;
	socialAccountInfo.setTextColor(getColor(android.R.color.black));
	socialAccountInfo.setText("");
}
 
Example 11
Source File: FacebookImpl.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
@Override
public com.codename1.io.AccessToken getAccessToken() {
    AccessToken fbToken = AccessToken.getCurrentAccessToken();
    if (fbToken != null) {
        String token = fbToken.getToken();
        Date ex = fbToken.getExpires();
        long diff = ex.getTime() - System.currentTimeMillis();
        diff = diff / 1000;
        com.codename1.io.AccessToken cn1Token = new com.codename1.io.AccessToken(token, "" + diff);
        return cn1Token;
    }
    return null;
}
 
Example 12
Source File: FacebookImpl.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the current session already has publish permissions
 *
 * @return
 */
public boolean hasPublishPermissions() {
    AccessToken fbToken = AccessToken.getCurrentAccessToken();
    if (fbToken != null && !fbToken.isExpired()) {
        return fbToken.getPermissions().contains(PUBLISH_PERMISSIONS.get(0));
    }
    return false;
}
 
Example 13
Source File: FirebaseHelper.java    From UberClone with MIT License 5 votes vote down vote up
public void registerByFacebookAccount(){
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    GraphRequest request = GraphRequest.newMeRequest(
            accessToken,
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    final String name=object.optString("name");
                    final String id=object.optString("id");
                    final String email=object.optString("email");
                    final User user=new User();
                    users.addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                            User post = dataSnapshot.child(id).getValue(User.class);

                            if(post==null) showRegisterPhone(user, id, name, email);
                            else loginSuccess();

                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError databaseError) {

                        }
                    });
                }
            });
    request.executeAsync();
}
 
Example 14
Source File: LoginWithFacebookSDKActivity.java    From Android-SDK with MIT License 5 votes vote down vote up
private void initUIBehaviour() {
	callbackManager = configureFacebookSDKLogin();

	fbLogoutBackendlessButton.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			if (isLoggedInBackendless)
				logoutFromBackendless();

			if (isLoggedInFacebook)
				logoutFromFacebook();
		}
	});

	if (AccessToken.getCurrentAccessToken() != null)
	{
		isLoggedInFacebook = true;
		fbAccessToken = AccessToken.getCurrentAccessToken().getToken();
	}

	BackendlessUser user = Backendless.UserService.CurrentUser();
	if (user != null)
	{
		isLoggedInBackendless = true;
		backendlessUserInfo.setTextColor(getColor(android.R.color.black));
		backendlessUserInfo.setText("Current user: " + user.getEmail());
		loginFacebookButton.setVisibility(View.INVISIBLE);
		fbLogoutBackendlessButton.setVisibility(View.VISIBLE);
	}
}
 
Example 15
Source File: FacebookProviderHandler.java    From capacitor-firebase-auth with MIT License 5 votes vote down vote up
@Override
public void fillResult(AuthCredential credential, JSObject jsResult) {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    if(accessToken != null && !accessToken.isExpired()) {
        jsResult.put("idToken", accessToken.getToken());
    }
}
 
Example 16
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 4 votes vote down vote up
public boolean isLogedIn() {
    return AccessToken.getCurrentAccessToken() != null || Twitter.getSessionManager().getActiveSession() != null || VKSdk.isLoggedIn();
}
 
Example 17
Source File: FacebookProvider.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isLoggedIn() {
    return AccessToken.getCurrentAccessToken() != null;
}
 
Example 18
Source File: ShareApi.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private void sharePhotoContent(final SharePhotoContent photoContent,
                               final FacebookCallback<Sharer.Result> callback) {
    final Mutable<Integer> requestCount = new Mutable<Integer>(0);
    final AccessToken accessToken = AccessToken.getCurrentAccessToken();
    final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>();
    final ArrayList<JSONObject> results = new ArrayList<JSONObject>();
    final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>();
    final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
        @Override
        public void onCompleted(GraphResponse response) {
            final JSONObject result = response.getJSONObject();
            if (result != null) {
                results.add(result);
            }
            if (response.getError() != null) {
                errorResponses.add(response);
            }
            requestCount.value -= 1;
            if (requestCount.value == 0) {
                if (!errorResponses.isEmpty()) {
                    ShareInternalUtility.invokeCallbackWithResults(
                            callback,
                            null,
                            errorResponses.get(0));
                } else if (!results.isEmpty()) {
                    final String postId = results.get(0).optString("id");
                    ShareInternalUtility.invokeCallbackWithResults(
                            callback,
                            postId,
                            response);
                }
            }
        }
    };
    try {
        for (SharePhoto photo : photoContent.getPhotos()) {
            final Bitmap bitmap = photo.getBitmap();
            final Uri photoUri = photo.getImageUrl();
            String caption = photo.getCaption();
            if (caption == null) {
                caption = this.getMessage();
            }
            if (bitmap != null) {
                requests.add(GraphRequest.newUploadPhotoRequest(
                        accessToken,
                        getGraphPath(PHOTOS_EDGE),
                        bitmap,
                        caption,
                        photo.getParameters(),
                        requestCallback));
            } else if (photoUri != null) {
                requests.add(GraphRequest.newUploadPhotoRequest(
                        accessToken,
                        getGraphPath(PHOTOS_EDGE),
                        photoUri,
                        caption,
                        photo.getParameters(),
                        requestCallback));
            }
        }
        requestCount.value += requests.size();
        for (GraphRequest request : requests) {
            request.executeAsync();
        }
    } catch (final FileNotFoundException ex) {
        ShareInternalUtility.invokeCallbackWithException(callback, ex);
    }
}
 
Example 19
Source File: MainActivity.java    From snippets-android with Apache License 2.0 4 votes vote down vote up
public void getFbCredentials() {
    AccessToken token = AccessToken.getCurrentAccessToken();
    // [START auth_fb_cred]
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    // [END auth_fb_cred]
}
 
Example 20
Source File: FacebookHelper.java    From AndroidBlueprints with Apache License 2.0 2 votes vote down vote up
/**
 * Is logged in boolean.
 *
 * @return the boolean result of if the user is currently connected
 */
public boolean isLoggedIn() {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    return accessToken != null;
}