1

I'm following this guide to create an app which sends an image to Facebook messenger.

String mimeType = "image/png";
Uri contentUri = Uri.parse("android.resource://com.test.test/drawable/foobar");

String metadata = "{ \"name\": \"baz\" }";
ShareToMessengerParams params = ShareToMessengerParams.newBuilder(contentUri, mimeType).setMetaData(metadata).build();
MessengerUtils.shareToMessenger(this, REQUEST_CODE_SHARE_TO_MESSENGER, params);

The code is pretty simple and almost identical to Facebook's own sample code. The image is properly sent to the messenger which recognizes my app to be optimized and supplies the REPLY button. However, I am having trouble getting the metadata sent across. When the REPLY button is pressed, everything that's supposed to be in the extra bundle (EXTRA_IS_REPLY, EXTRA_THREAD_TOKEN, EXTRA_PARTICIPANTS) is sent back to the app but not the metadata. Any help will be greatly appreciated.

Below is a snippet from manifest:

    <!-- Activities -->
    <activity
        android:name=".MainActivity"
        android:windowSoftInputMode="stateHidden"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PICK" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="com.facebook.orca.category.PLATFORM_THREAD_20150311"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PICK" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="com.facebook.orca.category.PLATFORM_THREAD_20150314"/>
        </intent-filter>
    </activity>

enter image description here

Community
  • 1
  • 1
DanielK
  • 792
  • 1
  • 6
  • 13

2 Answers2

3

Ok so here's the workaround for those having the same problem.

If an app posts a same image to Facebook Messenger multiple times, the Messenger treats all but the first image as duplicates and doesn't attach the metadata. (There's an eventual timeout but can't care less to figure out the exact duration)

My workaround is as follows: Every time your app posts to the messenger, make it place a random pixel in a random location to make sure the image's signature changes. I haven't tried but I think changing the alpha value of a pixel will work better in terms of making it less conspicuous to the users.

DanielK
  • 792
  • 1
  • 6
  • 13
  • I am facing the same problem. I am not able to get metadata back in my app. Does Facebook app needs approval for this functionality to work? – Sumit Chourasia Jul 09 '15 at 07:16
  • @SumitChourasia I don't think you need an approval for the basic set of functionalities to work. I suggest running Facebook's sample app contained in the SDK first and see if that works. – DanielK Jul 09 '15 at 23:15
  • Thanks @DanielK, this saved a lot of time! – kinshukkar Jul 24 '15 at 13:01
0

Yes, I can confirm that using a different image everytime does fix this issue.

yrizk
  • 394
  • 2
  • 8