如果应用程序没有安装,用户会收到Facebook请求数据吗



我目前正在我的应用程序中开发一项功能,该功能允许用户邀请他们的Facebook好友,为此他们和好友将获得奖励/礼物。

为此,我使用了Facebook请求选项。所以我查看了以下两个文档:

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 + "nn" + 
                                    "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以安装应用程序。在他安装应用程序并第一次打开它之后?有没有办法接收这些数据?

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在您明确删除请求之前不会删除请求,所以您不需要用于此交互的服务器端代码。

相关内容

  • 没有找到相关文章