Marche101
Marche101

Reputation: 825

Tag Friend in Picture using Facebook API in Android

I am having trouble tagging friends in pictures using the Facebook API in android. This is what I have at the moment

Bundle param;

    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.picture);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] data = stream.toByteArray();

    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    InputStream is = null;
    param = new Bundle();
    param.putString("message", dataMsg);
    param.putString("filename", "Invite");
    String[] numArr = invitedNum.toArray(new String[invitedNum.size()]); 
    param.putStringArray("message_tags",numArr);
    param.putByteArray("picture", data);
    mAsyncRunner.request("me/photos", param, "POST", new SampleUploadListener(), null);

    Toast.makeText(context, "Picture posted to Facebok.", Toast.LENGTH_SHORT).show();

This uploads the picture and sets a message on it but does not tag anybody in the picture. Any ideas would be really helpful.

Upvotes: 0

Views: 1319

Answers (1)

C Abernathy
C Abernathy

Reputation: 5523

To tag users, you'd need to follow the approach outlined here:

https://developers.facebook.com/docs/reference/api/photo/#tags

So you would:

1/ Upload the photo

2/ Get the photo ID (should be returned if the upload was successful)

3/ Make a call to this Graph API endpoint:

PHOTO_ID/tags 

and pass in the FB IDs in the tags parameter:

 tags=[{"id":"1234"}, {"id":"12345"}]. 

Upvotes: 2

Related Questions