本文整理匯總了Java中com.facebook.GraphResponse.getJSONObject方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphResponse.getJSONObject方法的具體用法?Java GraphResponse.getJSONObject怎麽用?Java GraphResponse.getJSONObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.facebook.GraphResponse
的用法示例。
在下文中一共展示了GraphResponse.getJSONObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shareLinkContent
import com.facebook.GraphResponse; //導入方法依賴的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();
}
示例2: getEventMap
import com.facebook.GraphResponse; //導入方法依賴的package包/類
/**
* Parses the response fetched from Facebook
* @param response response from Facebook's event end point
* @return a map from event names to events
*/
public static Map<String, FBEvent> getEventMap(GraphResponse response) {
Map<String, FBEvent> events = new HashMap<>();
try {
JSONObject jsonResponse = response.getJSONObject();
JSONArray data = jsonResponse.getJSONArray(DATA_KEY);
for (int i = 0; i < data.length(); i++) {
JSONObject fbEventJson = data.getJSONObject(i);
events.put(fbEventJson.getString(NAME_KEY), new FBEvent(fbEventJson));
}
}
catch(JSONException e) {
e.printStackTrace();
}
return events;
}
示例3: shareLinkContent
import com.facebook.GraphResponse; //導入方法依賴的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();
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(),
"/me/feed",
parameters,
HttpMethod.POST,
requestCallback).executeAsync();
}
示例4: shareLinkContent
import com.facebook.GraphResponse; //導入方法依賴的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(),
"/me/feed",
parameters,
HttpMethod.POST,
requestCallback).executeAsync();
}
示例5: executeGraphRequestSynchronously
import com.facebook.GraphResponse; //導入方法依賴的package包/類
protected void executeGraphRequestSynchronously(Bundle parameters) {
GraphRequest request = new GraphRequest(
uploadContext.accessToken,
String.format(Locale.ROOT, "%s/videos", uploadContext.graphNode),
parameters,
HttpMethod.POST,
null);
GraphResponse response = request.executeAndWait();
if (response != null) {
FacebookRequestError error = response.getError();
JSONObject responseJSON = response.getJSONObject();
if (error != null) {
if (!attemptRetry(error.getSubErrorCode())) {
handleError(new FacebookGraphResponseException(response, ERROR_UPLOAD));
}
} else if (responseJSON != null) {
try {
handleSuccess(responseJSON);
} catch (JSONException e) {
endUploadWithFailure(new FacebookException(ERROR_BAD_SERVER_RESPONSE, e));
}
} else {
handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE));
}
} else {
handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE));
}
}
示例6: handlePermissionResponse
import com.facebook.GraphResponse; //導入方法依賴的package包/類
/**
* This parses a server response to a call to me/permissions. It will return the list of
* granted permissions. It will optionally update an access token with the requested permissions.
*
* @param response The server response
* @return A list of granted permissions or null if an error
*/
private static PermissionsPair handlePermissionResponse(GraphResponse response) {
if (response.getError() != null) {
return null;
}
JSONObject result = response.getJSONObject();
if (result == null) {
return null;
}
JSONArray data = result.optJSONArray("data");
if (data == null || data.length() == 0) {
return null;
}
List<String> grantedPermissions = new ArrayList<String>(data.length());
List<String> declinedPermissions = new ArrayList<String>(data.length());
for (int i = 0; i < data.length(); ++i) {
JSONObject object = data.optJSONObject(i);
String permission = object.optString("permission");
if (permission == null || permission.equals("installed")) {
continue;
}
String status = object.optString("status");
if (status == null) {
continue;
}
if(status.equals("granted")) {
grantedPermissions.add(permission);
} else if (status.equals("declined")) {
declinedPermissions.add(permission);
}
}
return new PermissionsPair(grantedPermissions, declinedPermissions);
}
示例7: awaitGetGraphMeRequestWithCache
import com.facebook.GraphResponse; //導入方法依賴的package包/類
public static JSONObject awaitGetGraphMeRequestWithCache(
final String accessToken) {
JSONObject cachedValue = ProfileInformationCache.getProfileInformation(accessToken);
if (cachedValue != null) {
return cachedValue;
}
GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken);
GraphResponse response = graphRequest.executeAndWait();
if (response.getError() != null) {
return null;
}
return response.getJSONObject();
}
示例8: onCompleted
import com.facebook.GraphResponse; //導入方法依賴的package包/類
@Override
public void onCompleted(GraphResponse response) {
if (response.getError() == null && response.getJSONObject() != null && response.getJSONObject().has("id")) {
mAppLink = "https://fb.me/" + response.getJSONObject().opt("id");
updateView();
} else {
mAppLink = null;
updateView();
}
}
示例9: reloadUserInfo
import com.facebook.GraphResponse; //導入方法依賴的package包/類
/** {@inheritDoc} */
public void reloadUserInfo() {
clearUserInfo();
if (!isUserSignedIn()) {
return;
}
final Bundle parameters = new Bundle();
parameters.putString("fields", "name,picture.type(large)");
final GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), "me");
graphRequest.setParameters(parameters);
GraphResponse response = graphRequest.executeAndWait();
JSONObject json = response.getJSONObject();
try {
userName = json.getString("name");
userImageUrl = json.getJSONObject("picture")
.getJSONObject("data")
.getString("url");
} catch (final JSONException jsonException) {
Log.e(LOG_TAG,
"Unable to get Facebook user info. " + jsonException.getMessage() + "\n" + response,
jsonException);
// Nothing much we can do here.
}
}
示例10: shareVideoContent
import com.facebook.GraphResponse; //導入方法依賴的package包/類
private void shareVideoContent(final ShareVideoContent videoContent,
final FacebookCallback<Sharer.Result> callback) {
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
String postId = null;
if (response != null) {
JSONObject responseJSON = response.getJSONObject();
if (responseJSON != null) {
postId = responseJSON.optString("id");
}
}
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
};
GraphRequest videoRequest;
try {
videoRequest = ShareInternalUtility.newUploadVideoRequest(
AccessToken.getCurrentAccessToken(),
videoContent.getVideo().getLocalUrl(),
requestCallback);
} catch (final FileNotFoundException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
return;
}
final Bundle parameters = videoRequest.getParameters();
parameters.putString("title", videoContent.getContentTitle());
parameters.putString("description", videoContent.getContentDescription());
parameters.putString("ref", videoContent.getRef());
videoRequest.setParameters(parameters);
videoRequest.executeAsync();
}
示例11: executeGraphRequestSynchronously
import com.facebook.GraphResponse; //導入方法依賴的package包/類
protected void executeGraphRequestSynchronously(Bundle parameters) {
GraphRequest request = new GraphRequest(
uploadContext.accessToken,
String.format(Locale.ROOT, "%s/videos", uploadContext.targetId),
parameters,
HttpMethod.POST,
null);
GraphResponse response = request.executeAndWait();
if (response != null) {
FacebookRequestError error = response.getError();
JSONObject responseJSON = response.getJSONObject();
if (error != null) {
if (!attemptRetry(error.getSubErrorCode())) {
handleError(new FacebookGraphResponseException(response, ERROR_UPLOAD));
}
} else if (responseJSON != null) {
try {
handleSuccess(responseJSON);
} catch (JSONException e) {
endUploadWithFailure(new FacebookException(ERROR_BAD_SERVER_RESPONSE, e));
}
} else {
handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE));
}
} else {
handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE));
}
}
示例12: shareOpenGraphContent
import com.facebook.GraphResponse; //導入方法依賴的package包/類
private void shareOpenGraphContent(final ShareOpenGraphContent openGraphContent,
final FacebookCallback<Sharer.Result> callback) {
// In order to create a new Open Graph action using a custom object that does not already
// exist (objectID or URL), you must first send a request to post the object and then
// another to post the action. If a local image is supplied with the object or action, that
// must be staged first and then referenced by the staging URL that is returned by that
// request.
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 ShareOpenGraphAction action = openGraphContent.getAction();
final Bundle parameters = action.getBundle();
this.addCommonParameters(parameters, openGraphContent);
if (!Utility.isNullOrEmpty(this.getMessage())) {
parameters.putString("message", this.getMessage());
}
final CollectionMapper.OnMapperCompleteListener stageCallback = new CollectionMapper
.OnMapperCompleteListener() {
@Override
public void onComplete() {
try {
handleImagesOnAction(parameters);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
getGraphPath(
URLEncoder.encode(action.getActionType(), DEFAULT_CHARSET)),
parameters,
HttpMethod.POST,
requestCallback).executeAsync();
} catch (final UnsupportedEncodingException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}
@Override
public void onError(FacebookException exception) {
ShareInternalUtility.invokeCallbackWithException(callback, exception);
}
};
this.stageOpenGraphAction(parameters, stageCallback);
}
示例13: sharePhotoContent
import com.facebook.GraphResponse; //導入方法依賴的package包/類
private void sharePhotoContent(final SharePhotoContent photoContent,
final FacebookCallback<Sharer.Result> callback) {
final Mutable<Integer> requestCount = new Mutable<Integer>(0);
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>();
final ArrayList<JSONObject> results = new ArrayList<JSONObject>();
final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>();
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject result = response.getJSONObject();
if (result != null) {
results.add(result);
}
if (response.getError() != null) {
errorResponses.add(response);
}
requestCount.value -= 1;
if (requestCount.value == 0) {
if (!errorResponses.isEmpty()) {
ShareInternalUtility.invokeCallbackWithResults(
callback,
null,
errorResponses.get(0));
} else if (!results.isEmpty()) {
final String postId = results.get(0).optString("id");
ShareInternalUtility.invokeCallbackWithResults(
callback,
postId,
response);
}
}
}
};
try {
for (SharePhoto photo : photoContent.getPhotos()) {
final Bitmap bitmap = photo.getBitmap();
final Uri photoUri = photo.getImageUrl();
String caption = photo.getCaption();
if (caption == null) {
caption = this.getMessage();
}
if (bitmap != null) {
requests.add(GraphRequest.newUploadPhotoRequest(
accessToken,
getGraphPath(PHOTOS_EDGE),
bitmap,
caption,
photo.getParameters(),
requestCallback));
} else if (photoUri != null) {
requests.add(GraphRequest.newUploadPhotoRequest(
accessToken,
getGraphPath(PHOTOS_EDGE),
photoUri,
caption,
photo.getParameters(),
requestCallback));
}
}
requestCount.value += requests.size();
for (GraphRequest request : requests) {
request.executeAsync();
}
} catch (final FileNotFoundException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}
示例14: shareOpenGraphContent
import com.facebook.GraphResponse; //導入方法依賴的package包/類
private void shareOpenGraphContent(final ShareOpenGraphContent openGraphContent,
final FacebookCallback<Sharer.Result> callback) {
// In order to create a new Open Graph action using a custom object that does not already
// exist (objectID or URL), you must first send a request to post the object and then
// another to post the action. If a local image is supplied with the object or action, that
// must be staged first and then referenced by the staging URL that is returned by that
// request.
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 ShareOpenGraphAction action = openGraphContent.getAction();
final Bundle parameters = action.getBundle();
final CollectionMapper.OnMapperCompleteListener stageCallback = new CollectionMapper
.OnMapperCompleteListener() {
@Override
public void onComplete() {
try {
handleImagesOnAction(parameters);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/" + URLEncoder.encode(action.getActionType(), "UTF-8"),
parameters,
HttpMethod.POST,
requestCallback).executeAsync();
} catch (final UnsupportedEncodingException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}
@Override
public void onError(FacebookException exception) {
ShareInternalUtility.invokeCallbackWithException(callback, exception);
}
};
this.stageOpenGraphAction(parameters, stageCallback);
}
示例15: sharePhotoContent
import com.facebook.GraphResponse; //導入方法依賴的package包/類
private void sharePhotoContent(final SharePhotoContent photoContent,
final FacebookCallback<Sharer.Result> callback) {
final Mutable<Integer> requestCount = new Mutable<Integer>(0);
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>();
final ArrayList<JSONObject> results = new ArrayList<JSONObject>();
final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>();
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject result = response.getJSONObject();
if (result != null) {
results.add(result);
}
if (response.getError() != null) {
errorResponses.add(response);
}
requestCount.value -= 1;
if (requestCount.value == 0) {
if (!errorResponses.isEmpty()) {
ShareInternalUtility.invokeCallbackWithResults(
callback,
null,
errorResponses.get(0));
} else if (!results.isEmpty()) {
final String postId = results.get(0).optString("id");
ShareInternalUtility.invokeCallbackWithResults(
callback,
postId,
response);
}
}
}
};
try {
for (SharePhoto photo : photoContent.getPhotos()) {
final Bitmap bitmap = photo.getBitmap();
final Uri photoUri = photo.getImageUrl();
if (bitmap != null) {
requests.add(ShareInternalUtility.newUploadPhotoRequest(
accessToken,
bitmap,
requestCallback));
} else if (photoUri != null) {
requests.add(ShareInternalUtility.newUploadPhotoRequest(
accessToken,
photoUri,
requestCallback));
}
}
requestCount.value += requests.size();
for (GraphRequest request : requests) {
request.executeAsync();
}
} catch (final FileNotFoundException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}