Search in sources :

Example 16 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class ShareInternalUtility method newUploadStagingResourceWithImageRequest.

/**
     * 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 image       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
     */
public static GraphRequest newUploadStagingResourceWithImageRequest(AccessToken accessToken, Bitmap image, Callback callback) {
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(STAGING_PARAM, image);
    return new GraphRequest(accessToken, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback);
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle)

Example 17 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class DeviceAuthDialog method startLogin.

public void startLogin(final LoginClient.Request request) {
    this.mRequest = request;
    final Bundle parameters = new Bundle();
    parameters.putString("scope", TextUtils.join(",", request.getPermissions()));
    String redirectUriString = request.getDeviceRedirectUriString();
    if (redirectUriString != null) {
        parameters.putString("redirect_uri", redirectUriString);
    }
    String accessToken = Validate.hasAppID() + "|" + Validate.hasClientToken();
    parameters.putString(GraphRequest.ACCESS_TOKEN_PARAM, accessToken);
    parameters.putString(DeviceRequestsHelper.DEVICE_INFO_PARAM, DeviceRequestsHelper.getDeviceInfo());
    GraphRequest graphRequest = new GraphRequest(null, DEVICE_LOGIN_ENDPOINT, parameters, HttpMethod.POST, new GraphRequest.Callback() {

        @Override
        public void onCompleted(GraphResponse response) {
            if (isBeingDestroyed) {
                return;
            }
            if (response.getError() != null) {
                onError(response.getError().getException());
                return;
            }
            JSONObject jsonObject = response.getJSONObject();
            RequestState requestState = new RequestState();
            try {
                requestState.setUserCode(jsonObject.getString("user_code"));
                requestState.setRequestCode(jsonObject.getString("code"));
                requestState.setInterval(jsonObject.getLong("interval"));
            } catch (JSONException ex) {
                onError(new FacebookException(ex));
                return;
            }
            setCurrentRequestState(requestState);
        }
    });
    graphRequest.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) JSONException(org.json.JSONException)

Example 18 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class ShareInternalUtility method newUploadStagingResourceWithImageRequest.

/**
     * 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 imageUri    the file:// or content:// Uri pointing to 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, Uri imageUri, Callback callback) throws FileNotFoundException {
    if (Utility.isFileUri(imageUri)) {
        return newUploadStagingResourceWithImageRequest(accessToken, new File(imageUri.getPath()), callback);
    } else if (!Utility.isContentUri(imageUri)) {
        throw new FacebookException("The image Uri must be either a file:// or content:// Uri");
    }
    GraphRequest.ParcelableResourceWithMimeType<Uri> resourceWithMimeType = new GraphRequest.ParcelableResourceWithMimeType<>(imageUri, "image/png");
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(STAGING_PARAM, resourceWithMimeType);
    return new GraphRequest(accessToken, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback);
}
Also used : GraphRequest(com.facebook.GraphRequest) FacebookException(com.facebook.FacebookException) Bundle(android.os.Bundle) File(java.io.File) Uri(android.net.Uri)

Example 19 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class UserSettingsFragment method fetchUserInfo.

private void fetchUserInfo() {
    final AccessToken accessToken = AccessToken.getCurrentAccessToken();
    if (accessToken != null) {
        GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {

            @Override
            public void onCompleted(JSONObject me, GraphResponse response) {
                user = me;
                updateUI();
            }
        });
        Bundle parameters = new Bundle();
        parameters.putString(FIELDS, REQUEST_FIELDS);
        request.setParameters(parameters);
        GraphRequest.executeBatchAsync(request);
    } else {
        user = null;
    }
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) AccessToken(com.facebook.AccessToken) Bundle(android.os.Bundle)

Example 20 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class FacebookLoginActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_facebook_login);
    callbackManager = CallbackManager.Factory.create();
    fbLoginButton = (LoginButton) findViewById(R.id._fb_login);
    profilePictureView = (ProfilePictureView) findViewById(R.id.user_pic);
    profilePictureView.setCropped(true);
    userNameView = (TextView) findViewById(R.id.user_name);
    final Button deAuthButton = (Button) findViewById(R.id.deauth);
    deAuthButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (!isLoggedIn()) {
                Toast.makeText(FacebookLoginActivity.this, R.string.app_not_logged_in, Toast.LENGTH_LONG).show();
                return;
            }
            GraphRequest.Callback callback = new GraphRequest.Callback() {

                @Override
                public void onCompleted(GraphResponse response) {
                    try {
                        if (response.getError() != null) {
                            Toast.makeText(FacebookLoginActivity.this, getResources().getString(R.string.failed_to_deauth, response.toString()), Toast.LENGTH_LONG).show();
                        } else if (response.getJSONObject().getBoolean(SUCCESS)) {
                            LoginManager.getInstance().logOut();
                        // updateUI();?
                        }
                    } catch (JSONException ex) {
                    /* no op */
                    }
                }
            };
            GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), GRAPH_PATH, new Bundle(), HttpMethod.DELETE, callback);
            request.executeAsync();
        }
    });
    final Button permsButton = (Button) findViewById(R.id.perms);
    permsButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(final View v) {
            Intent selectPermsIntent = new Intent(FacebookLoginActivity.this, PermissionSelectActivity.class);
            startActivityForResult(selectPermsIntent, PICK_PERMS_REQUEST);
        }
    });
    // Callback registration
    fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(final LoginResult loginResult) {
            // App code
            Toast.makeText(FacebookLoginActivity.this, R.string.success, Toast.LENGTH_LONG).show();
            updateUI();
        }

        @Override
        public void onCancel() {
            // App code
            Toast.makeText(FacebookLoginActivity.this, R.string.cancel, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(final FacebookException exception) {
            // App code
            Toast.makeText(FacebookLoginActivity.this, R.string.error, Toast.LENGTH_LONG).show();
        }
    });
    new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(final Profile oldProfile, final Profile currentProfile) {
            updateUI();
        }
    };
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle) LoginResult(com.facebook.login.LoginResult) JSONException(org.json.JSONException) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) ProfilePictureView(com.facebook.login.widget.ProfilePictureView) Profile(com.facebook.Profile) FacebookCallback(com.facebook.FacebookCallback) ProfileTracker(com.facebook.ProfileTracker) Button(android.widget.Button) LoginButton(com.facebook.login.widget.LoginButton) GraphResponse(com.facebook.GraphResponse) FacebookException(com.facebook.FacebookException)

Aggregations

GraphRequest (com.facebook.GraphRequest)29 Bundle (android.os.Bundle)22 GraphResponse (com.facebook.GraphResponse)17 JSONObject (org.json.JSONObject)16 JSONException (org.json.JSONException)12 FacebookException (com.facebook.FacebookException)9 AccessToken (com.facebook.AccessToken)5 FacebookCallback (com.facebook.FacebookCallback)5 FacebookRequestError (com.facebook.FacebookRequestError)5 Uri (android.net.Uri)3 CollectionMapper (com.facebook.internal.CollectionMapper)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 View (android.view.View)1 Button (android.widget.Button)1