【问题标题】:Will the user receive Facebook request data if the application not installed?如果未安装应用程序,用户会收到 Facebook 请求数据吗?
【发布时间】:2013-12-05 15:38:12
【问题描述】:

我目前正在我的应用程序中开发一项功能,该功能允许用户邀请他们的 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 以安装应用程序。在他安装应用程序并第一次打开它之后?有没有办法接收这些数据?

【问题讨论】:

  • 目前没有。您需要在服务器端跟踪它(如果有的话)。
  • 如何在服务器中跟踪它?每次我的一个用户向他的每个朋友发送请求时,我都必须登录,然后验证该用户是否已登录我的应用程序。在我的情况下这是不可能的......
  • @MingLi Facebook 框架中是否有另一种方式来执行此操作?

标签: android facebook facebook-graph-api facebook-requests


【解决方案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 在您明确删除请求之前不会删除该请求,因此您不需要服务器端代码来进行此交互。

【讨论】:

    猜你喜欢
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-28
    相关资源
    最近更新 更多