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);
}
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();
}
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);
}
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;
}
}
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();
}
};
}
Aggregations