com.facebook.AccessToken Java Examples

The following examples show how to use com.facebook.AccessToken. 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: ShareApi.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #2
Source File: FireSignin.java    From Learning-Resources with MIT License 6 votes vote down vote up
private void firebaseAuthWithFacebook(AccessToken accessToken) {

        mPrgrsbrMain.setVisibility(View.VISIBLE);

        LogManager.printLog(LOGTYPE_INFO, "signInWithFacebookToken: " + accessToken);

        AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken());
        mFireAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        LogManager.printLog(LOGTYPE_DEBUG, "signInWithCredential:onComplete:" + task.isSuccessful());

                        if (!task.isSuccessful()) {

                            mPrgrsbrMain.setVisibility(View.GONE);
                            Log.w(LOG_TAG, "signInWithCredential", task.getException());
                            Snackbar.make(mCrdntrlyot, "Authentication failed.\n" + task.getException().getMessage(),
                                    Snackbar.LENGTH_LONG).show();
                        } else
                            successLoginGetData(task);
                    }
                });
    }
 
Example #3
Source File: LoginManager.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: FbLoginHiddenActivity.java    From SocialLoginManager with Apache License 2.0 6 votes vote down vote up
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
  try {
    SocialUser user = new SocialUser();
    user.userId = object.getString("id");
    user.accessToken = AccessToken.getCurrentAccessToken().getToken();
    user.photoUrl = String.format(PHOTO_URL, user.userId);
    SocialUser.Profile profile = new SocialUser.Profile();
    profile.email = object.has("email")? object.getString("email") : "";
    profile.name = object.has("name")? object.getString("name"): "";
    profile.pageLink = object.has("link")? object.getString("link"): "";
    user.profile = profile;
    SocialLoginManager.getInstance(this).onLoginSuccess(user);
  } catch (JSONException e) {
    SocialLoginManager.getInstance(this).onLoginError(e.getCause());
  }

  LoginManager.getInstance().logOut();

  finish();
}
 
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: 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 #7
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 #8
Source File: FacebookNetwork.java    From EasyLogin with MIT License 6 votes vote down vote up
@Override
public void onSuccess(LoginResult loginResult) {

    final AccessToken fbAccessToken = loginResult.getAccessToken();

    if (permissions.contains(EMAIL_PERMISSION_FIELD)) {
        addEmailToToken(fbAccessToken);
        return;
    }

    String token = fbAccessToken.getToken();
    String userId = fbAccessToken.getUserId();
    accessToken = new com.maksim88.easylogin.AccessToken.Builder(token)
            .userId(userId)
            .build();
    listener.onLoginSuccess(getNetwork());
}
 
Example #9
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 #10
Source File: ShareInternalUtility.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source File: VideoUploader.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
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();
            }
        }
    };
}
 
Example #12
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
private void fetchFacebookUserData(final IOperationFinishWithDataCallback profileFetched) {
    GraphRequest request = GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    userProfile = new UserProfile();
                    try {
                        StringBuilder userName = new StringBuilder();
                        if (object.has("first_name")) {
                            userName.append(object.getString("first_name"));
                        }
                        if (object.has("last_name")) {
                            userName.append(" ");
                            userName.append(object.getString("last_name"));
                        }
                        userProfile.setName(userName.toString());
                        String avatarUrl = "https://graph.facebook.com/" + object.getString("id") + "/picture?type=large";
                        userProfile.setProfileImageUrl(avatarUrl);
                        profileFetched.operationFinished(userProfile);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,first_name,email,last_name");
    request.setParameters(parameters);
    request.executeAsync();
}
 
Example #13
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
public String getLoginType() {
    if (Prefs.getString(SyncMaster.GLOBAL_TOKEN, null) != null) {
        return SyncMaster.TYPE_GLOBAL;
    } else if (AccessToken.getCurrentAccessToken() != null)
        return SyncMaster.TYPE_FB;
    else if (Twitter.getSessionManager().getActiveSession() != null) {
        return SyncMaster.TYPE_TWITTER;
    } else
        return SyncMaster.TYPE_VK;
}
 
Example #14
Source File: LoginDialogFragment.java    From openshop.io-android with MIT License 5 votes vote down vote up
/**
 * Volley request that sends FB_ID and FB_ACCESS_TOKEN to API
 */
private void verifyUserOnApi(JSONObject userProfileObject, AccessToken fbAccessToken) {
    String url = String.format(EndPoints.USER_LOGIN_FACEBOOK, SettingsMy.getActualNonNullShop(getActivity()).getId());
    JSONObject jo = new JSONObject();
    try {
        jo.put(JsonUtils.TAG_FB_ID, userProfileObject.getString("id"));
        jo.put(JsonUtils.TAG_FB_ACCESS_TOKEN, fbAccessToken.getToken());
    } catch (JSONException e) {
        Timber.e(e, "Exception while parsing fb user.");
        MsgUtils.showToast(getActivity(), MsgUtils.TOAST_TYPE_INTERNAL_ERROR, null, MsgUtils.ToastLength.LONG);
        return;
    }

    progressDialog.show();
    GsonRequest<User> verifyFbUser = new GsonRequest<>(Request.Method.POST, url, jo.toString(), User.class,
            new Response.Listener<User>() {
                @Override
                public void onResponse(@NonNull User response) {
                    Timber.d(MSG_RESPONSE, response.toString());
                    handleUserLogin(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (progressDialog != null) progressDialog.cancel();
            MsgUtils.logAndShowErrorMessage(getActivity(), error);
            LoginDialogFragment.logoutUser();
        }
    }, getFragmentManager(), null);
    verifyFbUser.setRetryPolicy(MyApplication.getDefaultRetryPolice());
    verifyFbUser.setShouldCache(false);
    MyApplication.getInstance().addToRequestQueue(verifyFbUser, CONST.LOGIN_DIALOG_REQUESTS_TAG);
}
 
Example #15
Source File: FacebookLoginActivity.java    From endpoints-samples with Apache License 2.0 5 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]

    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(FacebookLoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // [START_EXCLUDE]
                    hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}
 
Example #16
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 #17
Source File: RegisterActivity.java    From kute with Apache License 2.0 5 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);
    // [START_EXCLUDE silent]
    Toast.makeText(getApplicationContext(),"Facebook  show dialog",Toast.LENGTH_LONG).show();
    //showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    try{
                    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()) {
                        //make user partial login to logout
                        signOut();
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(RegisterActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // [START_EXCLUDE]
                    Toast.makeText(getApplicationContext(),"Facebook  hide dialog",Toast.LENGTH_LONG).show();
                    //hideProgressDialog();
                    // [END_EXCLUDE]
                    }
                    catch (Exception e){
                        e.printStackTrace();

                    }
                }
            });
}
 
Example #18
Source File: SignInBaseActivity.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private void handleFacebookAccessToken(final AccessToken token) {
    MyLg.d("KOI", "handleFacebookAccessToken:" + token);

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    MyLg.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                }
            });
}
 
Example #19
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 #20
Source File: MainActivity.java    From firebase-login-demo-android with MIT License 5 votes vote down vote up
private void onFacebookAccessTokenChange(AccessToken token) {
    if (token != null) {
        mAuthProgressDialog.show();
        mFirebaseRef.authWithOAuthToken("facebook", token.getToken(), new AuthResultHandler("facebook"));
    } else {
        // Logged out of Facebook and currently authenticated with Firebase using Facebook, so do a logout
        if (this.mAuthData != null && this.mAuthData.getProvider().equals("facebook")) {
            mFirebaseRef.unauth();
            setAuthenticatedUser(null);
        }
    }
}
 
Example #21
Source File: LoginActivity.java    From Simple-Blog-App with MIT License 5 votes vote down vote up
private void fbInit() {

        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();
        LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Log.d("facebook:token", AccessToken.getCurrentAccessToken().getToken());
                AccessToken.getCurrentAccessToken().getToken();
                signInWithFacebook(loginResult.getAccessToken());
            }

            @Override
            public void onCancel() {
                Log.d(TAG, "facebook:onCancel");
            }

            @Override
            public void onError(FacebookException error) {
                Log.d(TAG, "facebook:onError", error);
            }
        });
        fbImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this, Arrays.asList("email", "user_location", "user_birthday", "public_profile", "user_friends"));
            }
        });
    }
 
Example #22
Source File: FacebookHelper.java    From argus-android with Apache License 2.0 5 votes vote down vote up
public void logout() {
    if (AccessToken.getCurrentAccessToken() == null) {
        return;
        // already logged out
    }
    new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/",
            null, HttpMethod.DELETE, new GraphRequest
            .Callback() {
        @Override
        public void onCompleted(GraphResponse graphResponse) {
            LoginManager.getInstance().logOut();
        }
    }).executeAsync();
}
 
Example #23
Source File: FacebookHelper.java    From argus-android with Apache License 2.0 5 votes vote down vote up
public void initialize() {
    LoginManager.getInstance()
            .registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {

                    GraphRequest graphRequest = GraphRequest
                            .newMeRequest(loginResult.getAccessToken(),
                                    new GraphRequest.GraphJSONObjectCallback() {
                                        @Override
                                        public void onCompleted(JSONObject object,
                                                                GraphResponse response) {
                                            token = AccessToken.getCurrentAccessToken();
                                            if (resultListener != null) {
                                                resultListener.onSuccess(token);
                                            }
                                        }
                                    });
                    Bundle parameters = new Bundle();
                    graphRequest.setParameters(parameters);
                    graphRequest.executeAsync();
                }

                @Override
                public void onCancel() {
                }

                @Override
                public void onError(FacebookException error) {
                    resultListener.onFailure(error.getMessage());
                }
            });
}
 
Example #24
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 #25
Source File: FacebookNetwork.java    From EasyLogin with MIT License 5 votes vote down vote up
private void addEmailToToken(final AccessToken fbAccessToken) {
    GraphRequest meRequest = GraphRequest.newMeRequest(
            fbAccessToken, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject me, GraphResponse response) {
                    final String token = fbAccessToken.getToken();
                    final String userId = fbAccessToken.getUserId();
                    if (response.getError() != null) {
                        Log.d("FacebookNetwork", "Error occurred while fetching Facebook email");
                        accessToken = new com.maksim88.easylogin.AccessToken.Builder(token)
                                .userId(userId)
                                .build();
                        listener.onLoginSuccess(getNetwork());
                    } else {
                        final String email = me.optString(EMAIL_PERMISSION_FIELD);
                        final String name = me.optString(NAME_FIELD);
                        if (TextUtils.isEmpty(email)) {
                            Log.d("FacebookNetwork", "Email could not be fetched. The user might not have an email or have unchecked the checkbox while connecting.");
                        }
                        accessToken = new com.maksim88.easylogin.AccessToken.Builder(token)
                                .userId(userId)
                                .email(email)
                                .userName(name)
                                .build();
                        listener.onLoginSuccess(getNetwork());
                    }
                }
            });

    Bundle parameters = new Bundle();
    parameters.putString("fields", NAME_FIELD + "," + EMAIL_PERMISSION_FIELD);
    meRequest.setParameters(parameters);
    meRequest.executeAsync();
}
 
Example #26
Source File: ImportFriendsHelper.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
private void getFacebookFriendsList() {
    GraphRequest requestFriends = GraphRequest.newMyFriendsRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONArrayCallback() {
        @Override
        public void onCompleted(JSONArray objects, GraphResponse response) {
            Log.d("ImportFriendsHelper", objects.toString());
            if (objects.length() > 0) {
                for (int i = 0; i < objects.length(); i ++) {
                    try {
                        JSONObject elementFriend = (JSONObject) objects.get(i);
                        String userId = elementFriend.getString("id");
                        String userName = elementFriend.getString("name");
                        String userLink = elementFriend.getString("link");
                        friendsFacebookList.add(new InviteFriend(userId, userName, userLink,
                                InviteFriend.VIA_FACEBOOK_TYPE, null, false));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                fiendsReceived();
            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link");
    requestFriends.setParameters(parameters);
    requestFriends.executeAsync();
}
 
Example #27
Source File: AppEventsLogger.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor is private, newLogger() methods should be used to build an instance.
 */
private AppEventsLogger(Context context, String applicationId, AccessToken accessToken) {
    Validate.notNull(context, "context");
    this.contextName = Utility.getActivityName(context);

    if (accessToken == null) {
        accessToken = AccessToken.getCurrentAccessToken();
    }

    // If we have a session and the appId passed is null or matches the session's app ID:
    if (accessToken != null &&
            (applicationId == null || applicationId.equals(accessToken.getApplicationId()))
            ) {
        accessTokenAppId = new AccessTokenAppIdPair(accessToken);
    } else {
        // If no app ID passed, get it from the manifest:
        if (applicationId == null) {
            applicationId = Utility.getMetadataApplicationId(context);
        }
        accessTokenAppId = new AccessTokenAppIdPair(null, applicationId);
    }

    synchronized (staticLock) {

        if (applicationContext == null) {
            applicationContext = context.getApplicationContext();
        }
    }

    initializeTimersIfNeeded();
}
 
Example #28
Source File: UserRequest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
public static void makeUserRequest(GraphRequest.Callback callback) {
    final Bundle params = new Bundle();
    params.putString("fields", "name,id,email");
    final GraphRequest request = new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            ME_ENDPOINT,
            params,
            HttpMethod.GET,
            callback
    );
    request.executeAsync();
}
 
Example #29
Source File: LoginManager.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private LoginClient.Request createLoginRequest(Collection<String> permissions) {
    LoginClient.Request request = new LoginClient.Request(
            loginBehavior,
            Collections.unmodifiableSet(
                    permissions != null ? new HashSet(permissions) : new HashSet<String>()),
            defaultAudience,
            FacebookSdk.getApplicationId(),
            UUID.randomUUID().toString()
    );
    request.setRerequest(AccessToken.getCurrentAccessToken() != null);
    return request;
}
 
Example #30
Source File: LoginClient.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private Result(Parcel parcel) {
    this.code = Code.valueOf(parcel.readString());
    this.token = parcel.readParcelable(AccessToken.class.getClassLoader());
    this.errorMessage = parcel.readString();
    this.errorCode = parcel.readString();
    this.request = parcel.readParcelable(Request.class.getClassLoader());
    this.loggingExtras = Utility.readStringMapFromParcel(parcel);
}