本文整理汇总了Java中com.facebook.GraphRequest类的典型用法代码示例。如果您正苦于以下问题:Java GraphRequest类的具体用法?Java GraphRequest怎么用?Java GraphRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphRequest类属于com.facebook包,在下文中一共展示了GraphRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newUploadStagingResourceWithImageRequest
import com.facebook.GraphRequest; //导入依赖的package包/类
/**
* 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);
}
示例2: shareLinkContent
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例3: getGraphMeRequestWithCacheAsync
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例4: subscribeActual
import com.facebook.GraphRequest; //导入依赖的package包/类
@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();
}
示例5: getPermissions
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例6: revokePermission
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例7: revokeAccess
import com.facebook.GraphRequest; //导入依赖的package包/类
/** 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();
}
示例8: loadRequests
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例9: deleteRequest
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例10: getUserDataFromRequest
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例11: onSuccess
import com.facebook.GraphRequest; //导入依赖的package包/类
@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();
}
示例12: queryMe
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例13: facebookLogin
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例14: facebookLogin
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
示例15: createAppLinkIfNeeded
import com.facebook.GraphRequest; //导入依赖的package包/类
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();
}
}