Gary Kipnis
Gary Kipnis

Reputation: 732

How to Replace Facebook Photo Using GraphApi

Is it possible to replace an existing FB photo using GraphApi? I am using the following code snippet to attempt to replace the photo:

    GraphRequest fbUpload = new GraphRequest();
    Bundle fbUploadParams = new Bundle();
    fbUploadParams.putByteArray("source", imageData);
    fbUpload.setAccessToken(AccessToken.getCurrentAccessToken());
    fbUpload.setHttpMethod(HttpMethod.POST);
    if (photoUploadRecord.photoId != null) {
        fbUpload.setGraphPath(photoUploadRecord.photoId);
    } else {
        fbUpload.setGraphPath(photoUploadRecord.albumId + "/" + FloomitFb.FB_PHOTO_EDGE);
    }
    fbUpload.setParameters(fbUploadParams);
    GraphResponse response = fbUpload.executeAndWait();
    FacebookRequestError requestError = response.getError();

No error is returned, but the photo is not updated. The code looks at the photoId and if not null, then uses that as the GraphPath, which is what was described in documentation for the GraphApi for updating photos, but it was not clear if the photo update was simply referring to updating various fields associated with the photo (comments/tags/likes/etc...) or the image itself. This code successfully uploads a new photo (which is the case of photoId == null).

Upvotes: 0

Views: 268

Answers (1)

amudi
amudi

Reputation: 136

You can change the metadata but you can't change the actual photo itself. As stated in the documentation, source field is only available for reading.

Upvotes: 1

Related Questions