2

私は現在、ユーザーが Facebook の友達を招待できるようにするアプリケーションの機能を開発しています。そのために、ユーザーとその友達は報酬/ギフトを受け取ることができます。

そのため、Facebook リクエスト オプションを使用します。そこで、次の 2 つのドキュメントを調べました。

https://developers.facebook.com/docs/android/send-requests/

https://developers.facebook.com/docs/android/app-link-requests/

両方のデバイスにアプリケーションがインストールされていて、あるデバイスから別のデバイスにリクエストを送信し、送信者がこのメソッドを使用して送信した追加データを取得できる場合、これはうまく機能します。

    private void getRequestData(final String inRequestId) {
    // Create a new request for an HTTP GET with the
    // request ID as the Graph path.
    Request request = new Request(Session.getActiveSession(), 
            inRequestId, null, HttpMethod.GET, new Request.Callback() {

                @Override
                public void onCompleted(Response response) {
                    // Process the returned response
                    GraphObject graphObject = response.getGraphObject();
                    FacebookRequestError error = response.getError();
                    // Default message
                    String message = "Incoming request";
                    if (graphObject != null) 
                    {
                        CupsLog.d(TAG, "getRequestData -> graphObject != null: "+ graphObject.toString());
                        // Check if there is extra data
                        if (graphObject.getProperty("data") != null) 
                        {
                            CupsLog.d(TAG, "getRequestData -> graphObject.getProperty(data) != null");
                            try 
                            {
                                // Get the data, parse info to get the key/value info
                                JSONObject dataObject = new JSONObject((String)graphObject.getProperty("data"));
                                // Get the value for the key - badge_of_awesomeness
                                String reward = dataObject.getString("reward");
                                // Get the value for the key - social_karma
                                String coffeeCups = dataObject.getString("coffee_cups");
                                // Get the sender's name
                                JSONObject fromObject = (JSONObject) graphObject.getProperty("from");
                                String sender = fromObject.getString("name");
                                String title = sender+" sent you a gift";
                                // Create the text for the alert based on the sender
                                // and the data
                                message = title + "\n\n" + 
                                    "reward: " + reward + 
                                    " coffeeCups: " + coffeeCups;
                            } catch (JSONException e) {
                                message = "Error getting request info";
                            }
                        } else if (error != null) {
                            message = "Error getting request info";
                        }
                        else
                        {
                            CupsLog.d(TAG, "getRequestData -> graphObject.getProperty(data) == null");
                        }
                    }
                    Toast.makeText(SocialFeaturesActivity.this, message, Toast.LENGTH_LONG).show();
                }
        });
    // Execute the request asynchronously.
    Request.executeBatchAsync(request);
}

質問:受信者が Facebook でこのリクエストを受け取り、それをインストールしない場合、このリクエストは彼を Google Play にリダイレクトしてアプリをインストールします。アプリをインストールして初めて開いた後ですか? とにかくこのデータを受け取る方法はありますか?

4

1 に答える 1

1

Facebook は、保留中のリクエストがあるかどうか、アプリを開くたびに受信者が確認することを提案しています( を使用onResume)。/{user-id}/apprequests次のように、エンドポイントを使用して確認できます。

https://developers.facebook.com/docs/graph-api/reference/user/apprequests/

ドキュメントによると、GET はリクエスト オブジェクトの配列を返します。

API 呼び出しを行うアプリからこの人が受け取ったリクエスト

リクエスト ID を取得したら、次を使用して追加情報を収集できます。/{request-id}

https://developers.facebook.com/docs/graph-api/reference/request/

リクエストを処理したら、重複を避けるために削除してください。

Facebook はユーザーが明示的に削除するまでリクエストを削除しないため、このやり取りにサーバー側のコードは必要ありません。

于 2014-04-22T23:36:21.573 に答える