Java源码示例:com.facebook.HttpMethod

示例1
/**
 * 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
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
@SuppressLint("CheckResult")
@Override
public void fetchUserInfo(final BaseToken token) {
    Bundle params = new Bundle();
    params.putString("fields", "picture,name,id,email,permissions");

    request = new GraphRequest(((FacebookToken) token).getAccessTokenBean(),
            "/me", params, HttpMethod.GET, new GraphRequest.Callback() {
        @Override
        public void onCompleted(GraphResponse response) {
            try {
                if (response != null && response.getJSONObject() != null) {
                    ShareLogger.i(response.getJSONObject().toString());
                    FacebookUser faceBookUser = new FacebookUser(response.getJSONObject());
                    mLoginListener.loginSuccess(new LoginResultData(LoginPlatform.FACEBOOK, token, faceBookUser));
                } else {
                    mLoginListener.loginFailure(new JSONException("解析GraphResponse异常!!"), 303);
                }
                LoginUtil.recycle();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

    request.executeAsync();
}
 
示例4
/**
 * 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);
}
 
示例5
/**
 * 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);
}
 
示例6
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));
    }
}
 
示例7
private static GraphRequest getGraphMeRequestWithCache(
        final String accessToken) {
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,first_name,middle_name,last_name,link");
    parameters.putString("access_token", accessToken);
    GraphRequest graphRequest = new GraphRequest(
            null,
            "me",
            parameters,
            HttpMethod.GET,
            null);
    return graphRequest;
}
 
示例8
public void logout() {
    if (AccessToken.getCurrentAccessToken() == null) {
        return;
        // already logged out
    }
    new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/",
            null, HttpMethod.DELETE, new GraphRequest
            .Callback() {
        @Override
        public void onCompleted(GraphResponse graphResponse) {
            LoginManager.getInstance().logOut();
        }
    }).executeAsync();
}
 
示例9
public static void makeUserRequest(GraphRequest.Callback callback) {
    final Bundle params = new Bundle();
    params.putString("fields", "name,id,email");
    final GraphRequest request = new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            ME_ENDPOINT,
            params,
            HttpMethod.GET,
            callback
    );
    request.executeAsync();
}
 
示例10
private void publishStory(Session session) 
{
	Bundle postParams = new Bundle();
	postParams.putString("name", "Você Fiscal");

	// Receber os dados da eleição!!!
	postParams.putString("message", "Eu fiscalizei a seção: "+ this.secao +"\nNa zona eleitoral: " + this.zonaEleitoral + "\nNo município de: " + this.municipio);			
	postParams.putString("description", "Obrigado por contribuir com a democracia!");
	postParams.putString("link", "http://www.vocefiscal.org/");
	postParams.putString("picture", "http://imagizer.imageshack.us/v2/150x100q90/913/bAwPgx.png");

	Request.Callback callback= new Request.Callback() 
	{
		public void onCompleted(Response response) 
		{
			JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
			String postId = "Compartilhado com sucesso!";
			try 
			{
				postId = graphResponse.getString("Compartilhado com sucesso!");
			} catch (JSONException e) 
			{
			}
			FacebookRequestError error = response.getError();
			if (error != null) 
			{
				Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_SHORT).show();
			} else 
			{
				Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),	postId,	Toast.LENGTH_LONG).show();
			}
		}
	};

	Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);

	RequestAsyncTask task = new RequestAsyncTask(request);
	task.execute();
}
 
示例11
public static void getUserCoverImage(final Context context, final String fbid, final ImageView imageView, final FlowImageLoaderCallback callback){
    Bundle params = new Bundle();
    params.putString("fields", "cover");
    new Request(
            Session.getActiveSession(),
            "/" + fbid,
            params,
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {
                    GraphObject graphObject = response.getGraphObject();
                    if (graphObject != null && graphObject.getProperty("cover") != null) {
                        if (graphObject != null && graphObject.getProperty("cover") != null) {
                            try {
                                JSONObject json = graphObject.getInnerJSONObject();
                                String url = json.getJSONObject("cover").getString("source");
                                FlowImageLoader loader = new FlowImageLoader(context);
                                loader.loadImage(url, imageView, callback);
                            } catch (Exception e) {
                                Crashlytics.logException(e);
                            }
                        }
                    }
                }
            }
    ).executeAsync();
}
 
示例12
private void postImageToFacebook() {
    Session session = Session.getActiveSession();
    final Uri uri = (Uri) mExtras.get(Intent.EXTRA_STREAM);
    final String extraText = mPostTextView.getText().toString();
    if (session.isPermissionGranted("publish_actions"))
    {
        Bundle param = new Bundle();

        // Add the image
        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] byteArrayData = stream.toByteArray();
            param.putByteArray("picture", byteArrayData);
        } catch (IOException ioe) {
            // The image that was send through is now not there?
            Assert.assertTrue(false);
        }

        // Add the caption
        param.putString("message", extraText);
        Request request = new Request(session,"me/photos", param, HttpMethod.POST, new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                addNotification(getString(R.string.photo_post), response.getGraphObject(), response.getError());

            }
        }, null);
        RequestAsyncTask asyncTask = new RequestAsyncTask(request);
        asyncTask.execute();
        finish();
    }
}
 
示例13
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);
}
 
示例14
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例15
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例16
@Override
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例17
@Override
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例18
@Override
public HttpMethod getHttpMethod()
{
	return HttpMethod.DELETE;
}
 
示例19
public HttpMethod getHttpMethod()
{
	return HttpMethod.DELETE;
}
 
示例20
@Override
public HttpMethod getHttpMethod()
{
	return HttpMethod.GET;
}
 
示例21
@Override
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例22
public HttpMethod getHttpMethod()
{
	return HttpMethod.DELETE;
}
 
示例23
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例24
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例25
@Override
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例26
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例27
public HttpMethod getHttpMethod()
{
	return HttpMethod.POST;
}
 
示例28
@Override
public HttpMethod getHttpMethod()
{
	return HttpMethod.GET;
}
 
示例29
public HttpMethod getHttpMethod(); 
示例30
public HttpMethod getHttpMethod();