當前位置: 首頁>>代碼示例>>Java>>正文


Java GraphResponse.getJSONObject方法代碼示例

本文整理匯總了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();
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:26,代碼來源:ShareApi.java

示例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;
}
 
開發者ID:tidbit-team,項目名稱:tidbit-android,代碼行數:25,代碼來源:ParseUtil.java

示例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();
}
 
開發者ID:CE-KMITL-OOAD-2015,項目名稱:Move-Alarm_ORCA,代碼行數:24,代碼來源:ShareApi.java

示例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();
}
 
開發者ID:yudiandreanp,項目名稱:SocioBlood,代碼行數:26,代碼來源:ShareApi.java

示例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));
    }
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:30,代碼來源:VideoUploader.java

示例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);
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:44,代碼來源:LoginClient.java

示例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();
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:16,代碼來源:Utility.java

示例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();
    }
}
 
開發者ID:Turistforeningen,項目名稱:SjekkUT,代碼行數:11,代碼來源:CheckinAndSocialView.java

示例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.
    }
}
 
開發者ID:jtran064,項目名稱:PlatePicks-Android,代碼行數:28,代碼來源:FacebookSignInProvider.java

示例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();
}
 
開發者ID:CE-KMITL-OOAD-2015,項目名稱:Move-Alarm_ORCA,代碼行數:36,代碼來源:ShareApi.java

示例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));
    }
}
 
開發者ID:yudiandreanp,項目名稱:SocioBlood,代碼行數:30,代碼來源:VideoUploader.java

示例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);
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:49,代碼來源:ShareApi.java

示例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);
    }
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:69,代碼來源:ShareApi.java

示例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);
}
 
開發者ID:CE-KMITL-OOAD-2015,項目名稱:Move-Alarm_ORCA,代碼行數:43,代碼來源:ShareApi.java

示例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);
    }
}
 
開發者ID:CE-KMITL-OOAD-2015,項目名稱:Move-Alarm_ORCA,代碼行數:59,代碼來源:ShareApi.java


注:本文中的com.facebook.GraphResponse.getJSONObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。