本文整理匯總了Java中com.facebook.HttpMethod.POST屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethod.POST屬性的具體用法?Java HttpMethod.POST怎麽用?Java HttpMethod.POST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類com.facebook.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.POST屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newUploadStagingResourceWithImageRequest
/**
* 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: newPostOpenGraphObjectRequest
/**
* 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);
}
示例3: newUpdateOpenGraphObjectRequest
/**
* Creates a new Request configured to update a user owned Open Graph object.
*
* @param accessToken the access token to use, or null
* @param openGraphObject the Open Graph object to update, which must have a valid 'id'
* property
* @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 newUpdateOpenGraphObjectRequest(
AccessToken accessToken,
JSONObject openGraphObject,
Callback callback) {
if (openGraphObject == null) {
throw new FacebookException("openGraphObject cannot be null");
}
String path = openGraphObject.optString("id");
if (path == null) {
throw new FacebookException("openGraphObject must have an id");
}
Bundle bundle = new Bundle();
bundle.putString(OBJECT_PARAM, openGraphObject.toString());
return new GraphRequest(accessToken, path, bundle, HttpMethod.POST, callback);
}
示例4: newUploadPhotoRequest
/**
* Creates a new Request configured to upload a photo to the user's default photo album. The
* photo will be read from the specified Uri.
* @param accessToken the access token to use, or null
* @param photoUri the file:// or content:// Uri to the photo on device.
* @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 newUploadPhotoRequest(
AccessToken accessToken,
Uri photoUri,
Callback callback)
throws FileNotFoundException {
if (Utility.isFileUri(photoUri)) {
return newUploadPhotoRequest(accessToken, new File(photoUri.getPath()), callback);
} else if (!Utility.isContentUri(photoUri)) {
throw new FacebookException("The photo Uri must be either a file:// or content:// Uri");
}
Bundle parameters = new Bundle(1);
parameters.putParcelable(PICTURE_PARAM, photoUri);
return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback);
}
示例5: newUploadVideoRequest
/**
* Creates a new Request configured to upload a photo to the user's default photo album. The
* photo will be read from the specified Uri.
* @param accessToken the access token to use, or null
* @param videoUri the file:// or content:// Uri to the video on device.
* @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 newUploadVideoRequest(
AccessToken accessToken,
Uri videoUri,
Callback callback)
throws FileNotFoundException {
if (Utility.isFileUri(videoUri)) {
return newUploadVideoRequest(accessToken, new File(videoUri.getPath()), callback);
} else if (!Utility.isContentUri(videoUri)) {
throw new FacebookException("The video Uri must be either a file:// or content:// Uri");
}
Bundle parameters = new Bundle(1);
parameters.putParcelable(PICTURE_PARAM, videoUri);
return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback);
}
示例6: newStatusUpdateRequest
/**
* Creates a new Request configured to post a status update to a user's feed.
*
* @param accessToken the access token to use, or null
* @param message the text of the status update
* @param placeId an optional place id to associate with the post
* @param tagIds an optional list of user ids to tag in the post
* @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
*/
private static GraphRequest newStatusUpdateRequest(
AccessToken accessToken,
String message,
String placeId,
List<String> tagIds,
Callback callback) {
Bundle parameters = new Bundle();
parameters.putString("message", message);
if (placeId != null) {
parameters.putString("place", placeId);
}
if (tagIds != null && tagIds.size() > 0) {
String tags = TextUtils.join(",", tagIds);
parameters.putString("tags", tags);
}
return new GraphRequest(accessToken, MY_FEED, parameters, HttpMethod.POST, callback);
}
示例7: newUploadPhotoRequest
/**
* Creates a new Request configured to upload a photo to the user's default photo album. The
* photo will be read from the specified file.
*
* @param accessToken the access token to use, or null
* @param file the file containing the photo to upload
* @param caption the user generated caption for the photo.
* @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 java.io.FileNotFoundException
*/
public static GraphRequest newUploadPhotoRequest(
AccessToken accessToken,
File file,
String caption,
Callback callback
) throws FileNotFoundException {
ParcelFileDescriptor descriptor =
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
Bundle parameters = new Bundle(1);
parameters.putParcelable(PICTURE_PARAM, descriptor);
if (caption != null && !caption.isEmpty()) {
parameters.putString(CAPTION_PARAM, caption);
}
return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback);
}
示例8: createAlbum
private void createAlbum() {
// TODO Auto-generated method stub
Bundle params = new Bundle();
params.putString("name", ViewStory.this.story.getName());
params.putString("message", ViewStory.this.story.getComment());
Request request = new Request(MainActivity.session, "me/albums", params,
HttpMethod.POST);
request.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
// TODO Auto-generated method stub
try {
jo = response.getGraphObject().getInnerJSONObject().getJSONArray("data").getJSONObject(0);
Toast.makeText(ViewStory.this, "ALBUM CREATION COMPLETED\n", Toast.LENGTH_LONG).show();
uploadImagesToAlbum(jo);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ViewStory.this, "ALBUM CREATION FAILED\n", Toast.LENGTH_LONG).show();
}
}
});
request.executeAsync();
}
示例9: uploadImagesToAlbum
private void uploadImagesToAlbum(JSONObject jo) throws JSONException {
// TODO Auto-generated method stub
ArrayList<Photo> photos = db.get_photos(ViewStory.this.story.getId());
for (int i = 0; i < photos.size(); i++) {
String imgUrl = photos.get(i).getUrl();
Bitmap bmp = BitmapFactory.decodeFile(imgUrl);
String imgComment = photos.get(i).getComment();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Bundle params = new Bundle();
params.putByteArray("source", byteArray);
params.putString("message", imgComment);
Request rr = new Request(MainActivity.session, jo.getString("id")+"/photos", params, HttpMethod.POST);
rr.setCallback(new Callback() {
@Override
public void onCompleted(Response response) {
// TODO Auto-generated method stub
Toast.makeText(ViewStory.this, "PHOTO ADDED SUCESSFULLY", Toast.LENGTH_LONG).show();
}
});
rr.executeAsync();
}
}
示例10: executeGraphRequestSynchronously
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));
}
}
示例11: publishStory
private void publishStory(final String message) {
if (AccessToken.getCurrentAccessToken() != null) {
Bundle postParams = new Bundle();
postParams.putString("message", message);
GraphRequest.Callback callback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
FacebookRequestError error = graphResponse.getError();
if (error != null) {
if (eventHandler != null) {
Log.sysOut("$#$#$ " + error);
eventHandler.stopProgress();
eventHandler.onFacebookError(error
.getErrorMessage());
}
return;
}
if (eventHandler != null) {
eventHandler.stopProgress();
eventHandler.onRecievePost(message);
}
}
};
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "feed", postParams,
HttpMethod.POST, callback);
request.executeAsync();
} else if (eventHandler != null) eventHandler.onFacebookError(activity.getString(R.string.facebook_you_must_login_first_toast));
}
示例12: executeGraphRequestSynchronously
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));
}
}
示例13: postComments
/**
* @param post_id
* @param message
* @param callback
*/
public void postComments(String post_id, String message, Callback callback) {
Bundle bundle = new Bundle();
bundle.putString("message", message);
GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(),
"/" + post_id + "/comments",
bundle,
HttpMethod.POST,
DefaultCallback(callback));
graphRequest.executeAsync();
}
示例14: publishStory
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();
}
示例15: postImageToFacebook
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();
}
}