Question

I am trying to upload images from a Url to facebook.

Ideally I would like to create an album (based on some text input) Then upload some images into that album using the URL of the images (which will be in an ArrayList). I don't want to download the photo first, and then have to reupload - I just want to add them to the album using the URLs of the images.

I'm seen a lot of confusing information on how to do this. Can anyone offer some clarity?

Is it possible to do this with newUploadPhotoRequest?

Here is the code I tried to use as a test, it posts ok but it just posts to the timeline as a link. Ideally I want to upload to a new album - I already have the album id.

Request.Callback callback= new Request.Callback()
            {
                public void onCompleted(com.facebook.Response response)
                {
                    FacebookRequestError error = response.getError();
                    if (error != null)
                        Toast.makeText(getApplicationContext(), error.getErrorMessage(), Toast.LENGTH_SHORT).show();
                    else
                        Toast.makeText(getApplicationContext(), "Posted successfully.", Toast.LENGTH_LONG).show();
                }
            };

           Session session = Session.getActiveSession();


            Bundle postParams = new Bundle();

            postParams.putString("name", "Title");
            postParams.putString("link", "http://www.stackoverflow.com");
            postParams.putString("description", "description");
            postParams.putString("caption", "PictureTestApp");
            postParams.putString("picture", "https://www.myURLinhere/IMG_20110923_194535.jpg");

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

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
Was it helpful?

Solution

This is the answer:

Bundle params = new Bundle();
params.putString("url", "{image-url}");
/* make the API call */
new Request(
    session,
    "/{album-id}/photos",
    params,
    HttpMethod.POST,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top