/**
* 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);
}
java类com.facebook.GraphRequest的实例源码
ShareInternalUtility.java 文件源码
项目:kognitivo
阅读 69
收藏 0
点赞 0
评论 0
ShareApi.java 文件源码
项目:kognitivo
阅读 32
收藏 0
点赞 0
评论 0
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();
}
Utility.java 文件源码
项目:kognitivo
阅读 34
收藏 0
点赞 0
评论 0
public static void getGraphMeRequestWithCacheAsync(
final String accessToken,
final GraphMeRequestWithCacheCallback callback) {
JSONObject cachedValue = ProfileInformationCache.getProfileInformation(accessToken);
if (cachedValue != null) {
callback.onSuccess(cachedValue);
return;
}
GraphRequest.Callback graphCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
if (response.getError() != null) {
callback.onFailure(response.getError().getException());
} else {
ProfileInformationCache.putProfileInformation(
accessToken,
response.getJSONObject());
callback.onSuccess(response.getJSONObject());
}
}
};
GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken);
graphRequest.setCallback(graphCallback);
graphRequest.executeAsync();
}
RxFacebookGraphRequestSingle.java 文件源码
项目:RxFacebook
阅读 29
收藏 0
点赞 0
评论 0
@Override
protected void subscribeActual(@NonNull SingleObserver<? super GraphResponse> observer) {
mObserver = observer;
GraphRequest request = GraphRequest.newMeRequest(mAccessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (response.getError() == null) {
mObserver.onSuccess(response);
} else {
mObserver.onError(response.getError().getException());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", mFields);
request.setParameters(parameters);
request.executeAsync();
}
FacebookSignIn.java 文件源码
项目:GodotFireBase
阅读 20
收藏 0
点赞 0
评论 0
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();
}
FacebookSignIn.java 文件源码
项目:GodotFireBase
阅读 26
收藏 0
点赞 0
评论 0
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();
}
FacebookSignIn.java 文件源码
项目:GodotFireBase
阅读 21
收藏 0
点赞 0
评论 0
/** 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();
}
FacebookSDK.java 文件源码
项目:GDFacebook
阅读 36
收藏 0
点赞 0
评论 0
public void loadRequests() {
AccessToken token = AccessToken.getCurrentAccessToken();
GraphRequest myRequests = GraphRequest.newGraphPathRequest(
token, "/me/apprequests", new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
if (error == null) {
JSONObject graphObject = response.getJSONObject();
JSONArray data = graphObject.optJSONArray("data");
Utils.callScriptFunc("pendingRequest", data.toString());
} else { Utils.d("Response Error: " + error.toString()); }
}
});
myRequests.executeAsync();
}
FacebookSDK.java 文件源码
项目:GDFacebook
阅读 30
收藏 0
点赞 0
评论 0
public static void deleteRequest (String requestId) {
// delete Requets here GraphAPI.
Utils.d("Deleting:Request:" + requestId);
AccessToken token = AccessToken.getCurrentAccessToken();
GraphRequest graphRequest = GraphRequest.newDeleteObjectRequest(
token, requestId, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
if (error == null) { Utils.d("OnDelete:Req:" + response.toString()); }
}
});
graphRequest.executeAsync();
}
FacebookSDK.java 文件源码
项目:GDFacebook
阅读 32
收藏 0
点赞 0
评论 0
public static void getUserDataFromRequest (String requestId) {
// Grah Api to get user data from request.
AccessToken token = AccessToken.getCurrentAccessToken();
GraphRequest graphRequest = GraphRequest.newGraphPathRequest(
token, requestId, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
if (error == null) { Utils.d("Response: " + response.toString()); }
else { Utils.d("Error: " + response.toString()); }
}
});
graphRequest.executeAsync();
}
ActivityLaunchScreen.java 文件源码
项目:lecrec-android
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
String socialId = null, name = null;
try {
socialId = object.getString("id");
name = object.getString("name");
}catch (Exception e){}
register(socialId, name);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name");
request.setParameters(parameters);
request.executeAsync();
}
ApnFbLoginPlugin.java 文件源码
项目:apn_fb_login
阅读 22
收藏 0
点赞 0
评论 0
private void queryMe(Result result) {
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
(object, response) -> {
try {
result.success(JsonConverter.convertToMap(object));
} catch (JSONException e) {
result.error(TAG, "Error", e.getMessage());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
LoginActivity.java 文件源码
项目:2017.1-Trezentos
阅读 36
收藏 0
点赞 0
评论 0
private void facebookLogin(LoginResult loginResult){
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(JSONObject object, GraphResponse response){
JSONObject jsonObject = response.getJSONObject();
UserAccountControl userAccountControl = UserAccountControl
.getInstance(getApplicationContext());
userAccountControl.authenticateLoginFb(object);
userAccountControl.logInUserFromFacebook(jsonObject);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender");
request.setParameters(parameters);
request.executeAsync();
}
LoginActivity.java 文件源码
项目:2017.1-Trezentos
阅读 25
收藏 0
点赞 0
评论 0
private void facebookLogin(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
UserAccountControl userAccountControl = UserAccountControl
.getInstance(getApplicationContext());
userAccountControl.authenticateLoginFb(object);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender");
request.setParameters(parameters);
request.executeAsync();
}
CheckinAndSocialView.java 文件源码
项目:SjekkUT
阅读 26
收藏 0
点赞 0
评论 0
private void createAppLinkIfNeeded() {
if (mPlace != null && mAppLink == null && Utils.isConnected(getContext())) {
String token = getContext().getString(R.string.facebook_app_id) + "|" +
getContext().getString(R.string.facebook_app_secret);
Bundle parameters = new Bundle();
parameters.putString("name", "Sjekk Ut");
parameters.putString("access_token", token);
parameters.putString("web", "{\"should_fallback\": false}");
parameters.putString("iphone", "[{\"url\": \"sjekkut://place/" + mPlace.getId() + "\"}]");
parameters.putString("android", "[{\"url\": \"no.dnt.sjekkut://place/" + mPlace.getId() + "\", \"package\": \"no.dnt.sjekkut\"}]");
new GraphRequest(
null,
"/app/app_link_hosts",
parameters,
HttpMethod.POST,
this).executeAsync();
}
}
FacebookManager.java 文件源码
项目:eazysocial
阅读 27
收藏 0
点赞 0
评论 0
@Override
public void onSuccess(LoginResult loginResult) {
final String fbAccessToken = loginResult.getAccessToken().getToken();
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(TOKEN_FB_KEY,fbAccessToken);
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (onFacebookEvent != null) {
InfoSocial infoSocial = new InfoSocial();
infoSocial.setAccessToken(fbAccessToken);
infoSocial.setName(object.optString("name"));
infoSocial.setEmail(object.optString("email"));
infoSocial.setUserId(object.optString("id"));
onFacebookEvent.onFacebookSuccess(infoSocial);
}
}
});
request.setParameters(parameters);
request.executeAsync();
}
FacebookSignUpAdapter.java 文件源码
项目:aptoide-client-v8
阅读 21
收藏 0
点赞 0
评论 0
private Single<String> getFacebookEmail(AccessToken accessToken) {
return Single.defer(() -> {
try {
final GraphResponse response = GraphRequest.newMeRequest(accessToken, null)
.executeAndWait();
final JSONObject object = response.getJSONObject();
if (response.getError() == null && object != null) {
try {
return Single.just(
object.has("email") ? object.getString("email") : object.getString("id"));
} catch (JSONException ignored) {
return Single.error(
new FacebookSignUpException(FacebookSignUpException.ERROR, "Error parsing email"));
}
} else {
return Single.error(new FacebookSignUpException(FacebookSignUpException.ERROR,
"Unknown error(maybe network error when getting user data)"));
}
} catch (RuntimeException exception) {
return Single.error(
new FacebookSignUpException(FacebookSignUpException.ERROR, exception.getMessage()));
}
})
.subscribeOn(Schedulers.io());
}
FacebookProvider.java 文件源码
项目:assistance-platform-client-sdk-android
阅读 21
收藏 0
点赞 0
评论 0
/**
* Requests user graph data
* Use permission parameters e.g. "id, first_name, last_name, email, gender"
*
* @param accessToken
* @param permissionParams
* @param onFacebookGraphResponse
*/
public void requestGraphData(final AccessToken accessToken,
String permissionParams,
final OnFacebookGraphResponse onFacebookGraphResponse) {
GraphRequest request = GraphRequest.newMeRequest(accessToken,
(object, response) -> {
if (object == null) {
Log.d(TAG, "Response is null");
return;
}
Log.d(TAG, "Object received: " + object.toString());
onFacebookGraphResponse.onCompleted(object, response);
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", permissionParams);
request.setParameters(parameters);
request.executeAsync();
}
FacebookFriendlistLoader.java 文件源码
项目:EmbeddedSocial-Android-SDK
阅读 19
收藏 0
点赞 0
评论 0
@Override
public List<String> getThirdPartyFriendIds() throws SocialNetworkException {
if (!isAuthorizedToSocialNetwork()) {
throw new NotAuthorizedToSocialNetworkException();
}
GraphResponse response = new GraphRequest(
facebookTokenHolder.getToken(),
FACEBOOK_FRIENDS_GRAPH_PATH,
Bundle.EMPTY,
HttpMethod.GET
).executeAndWait();
facebookTokenHolder.clearToken();
FacebookRequestError responseError = response.getError();
if (responseError != null) {
throw new SocialNetworkException("Internal facebook failure: "
+ responseError.getErrorMessage() + " [" + responseError.getErrorCode() + "]");
}
return extractFacebookFriendIds(response);
}
FacebookSdkHelper.java 文件源码
项目:The_busy_calendar
阅读 20
收藏 0
点赞 0
评论 0
public void setPhoto(final ImageView imageView, final Button button){
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"me?fields=picture.width(500).height(500)",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
try {
Log.d("LOG onComplete", String.valueOf(AccessToken.getCurrentAccessToken()));
String url=new FacebookJsonParse().FacebookImageParse(response.getJSONObject());
imageView.setVisibility(View.VISIBLE);
button.setVisibility(View.GONE);
Glide.with(context).load(url).into(imageView);
} catch (JSONException e) {
Log.d("FacebookSdkHelper",e.getMessage());
}
}
}
).executeAsync();
}
RequestAction.java 文件源码
项目:ReactiveFB
阅读 27
收藏 0
点赞 0
评论 0
protected void execute() {
if (sessionManager.isLoggedIn()) {
AccessToken accessToken = sessionManager.getAccessToken();
Bundle bundle = updateAppSecretProof();
GraphRequest request = new GraphRequest(accessToken, getGraphPath(),
bundle, HttpMethod.GET);
request.setVersion(configuration.getGraphVersion());
runRequest(request);
} else {
String reason = Errors.getError(Errors.ErrorMsg.LOGIN);
Logger.logError(getClass(), reason, null);
if (mSingleEmitter != null) {
mSingleEmitter.onError(new FacebookAuthorizationException(reason));
}
}
}
SignUpActivity.java 文件源码
项目:zum-android
阅读 27
收藏 0
点赞 0
评论 0
private void getUserEmail(AccessToken accessToken) {
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
updateUserData(object.getString("email"));
} catch (JSONException e) {
updateUserData("");
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,email");
request.setParameters(parameters);
request.executeAsync();
}
FbUserDataActivity.java 文件源码
项目:Simple-Facebook-Login
阅读 21
收藏 0
点赞 0
评论 0
private void getFBUserInfo(final UserDataCallback userDataCallback) {
final FBUser fbUser = new FBUser();
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
fbUser.username = object.getString("name");
fbUser.userId = object.getString("id");
userDataCallback.userData(fbUser);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
request.executeAsync();
}
FbPageInfoFragment.java 文件源码
项目:journal
阅读 17
收藏 0
点赞 0
评论 0
public void pageAbout(final String pageId){
GraphRequest request = GraphRequest.newGraphPathRequest(
AccessToken.getCurrentAccessToken(),
"/"+pageId,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
JSONObject object = response.getJSONObject();
String about = object.optString("about");
pageAbout_tv = (TextView)getActivity().findViewById(R.id.pageAbout);
pageAbout_tv.setText(about);
String description = object.optString("description");
pageAbout_tv = (TextView)getActivity().findViewById(R.id.pageDescription);
pageAbout_tv.setText(about);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "about,description");
request.setParameters(parameters);
request.executeAsync();
}
SignInActivity.java 文件源码
项目:bitdate
阅读 27
收藏 0
点赞 0
评论 0
private void getFacebookInfo() {
Bundle parameters = new Bundle();
parameters.putString("fields", "picture, first_name, id");
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", parameters, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
JSONObject user = graphResponse.getJSONObject();
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.put("firstName", user.optString("first_name"));
currentUser.put("facebookId", user.optString("id"));
currentUser.put("pictureURL", user.optJSONObject("picture").optJSONObject("data").optString("url"));
currentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if(e == null) {
Log.i(TAG, "User saved");
setResult(RESULT_OK);
finish();
}
}
});
}
}).executeAsync();
}
FacebookHandler.java 文件源码
项目:android-fagyi
阅读 26
收藏 0
点赞 0
评论 0
public void getFurtherInfoAboutMe(final ProfileInformationCallback callback) {
GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject me, GraphResponse response) {
if (response.getError() != null) {
// handle error
callback.onReady(null);
} else {
FacebookUser user = getUser();
String email = me.optString("email");
if (email != null)
user.email = email;
callback.onReady(user);
}
}
}).executeAsync();
}
NewEventFragment.java 文件源码
项目:tidbit-android
阅读 22
收藏 0
点赞 0
评论 0
/**
* Attempts to get a list of the user's visible
* events from his/her facebook
*/
private void getEventListFromFacebook() {
if (InternetUtil.isOnline(getActivity())) {
SessionManager manager = new SessionManager(getActivity());
AccessToken token = manager.getAccessToken();
String path = manager.getString(getString(R.string.fb_field_id)) + "/events";
Bundle params = new Bundle();
params.putString(getString(R.string.fb_fields_key), getString(R.string.fb_ev_fields));
GraphRequest request = GraphRequest.newGraphPathRequest(token, path, this);
request.setParameters(params);
request.executeAsync();
}
else {
showNoInternetSnackBar();
}
}
ViewPerson.java 文件源码
项目:Studddinv2_android
阅读 21
收藏 0
点赞 0
评论 0
private boolean makeMeRequest() {
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
try {
facebook.setVisibility(View.VISIBLE);
if(object!=null)
facebookId = object.getString("id");
} catch (JSONException e1) {
e1.printStackTrace();
}
}
});
request.executeAsync();
return false;
}
ShareInternalUtility.java 文件源码
项目:Move-Alarm_ORCA
阅读 21
收藏 0
点赞 0
评论 0
/**
* Creates a new Request configured to create a user owned Open Graph object.
*
* @param accessToken the accessToken to use, or null
* @param openGraphObject the Open Graph object to create; must not be null, and must have a
* non-empty type and title
* @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 newPostOpenGraphObjectRequest(
AccessToken accessToken,
JSONObject openGraphObject,
Callback callback) {
if (openGraphObject == null) {
throw new FacebookException("openGraphObject cannot be null");
}
if (Utility.isNullOrEmpty(openGraphObject.optString("type"))) {
throw new FacebookException("openGraphObject must have non-null 'type' property");
}
if (Utility.isNullOrEmpty(openGraphObject.optString("title"))) {
throw new FacebookException("openGraphObject must have non-null 'title' property");
}
String path = String.format(MY_OBJECTS_FORMAT, openGraphObject.optString("type"));
Bundle bundle = new Bundle();
bundle.putString(OBJECT_PARAM, openGraphObject.toString());
return new GraphRequest(accessToken, path, bundle, HttpMethod.POST, callback);
}
ShareInternalUtility.java 文件源码
项目:Move-Alarm_ORCA
阅读 23
收藏 0
点赞 0
评论 0
/**
* Creates a new Request configured to publish an Open Graph action.
*
* @param accessToken the access token to use, or null
* @param openGraphAction the Open Graph action to create; must not be null, and must have a
* non-empty 'type'
* @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 newPostOpenGraphActionRequest(
AccessToken accessToken,
JSONObject openGraphAction,
Callback callback) {
if (openGraphAction == null) {
throw new FacebookException("openGraphAction cannot be null");
}
String type = openGraphAction.optString("type");
if (Utility.isNullOrEmpty(type)) {
throw new FacebookException("openGraphAction must have non-null 'type' property");
}
String path = String.format(MY_ACTION_FORMAT, type);
return GraphRequest.newPostRequest(accessToken, path, openGraphAction, callback);
}