使用Android中的"请求对话框"向Facebook中的所有朋友发送应用请求

Gug*_*gan 12 android facebook-graph-api facebook-app-requests facebook-friends facebook-invite-friends

我想知道如何从Android应用程序向我的所有Facebook朋友发送应用程序请求.我试过图API.但是,无法完成它.

https://graph.facebook.com/apprequests?ids=friend1,friend2&message='Hi'&method=post&access_token=ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)

我知道这是一个重复的问题.但是,还没找到答案.我在上面的API上遇到了这个错误.

"All users in param ids must have accepted TOS."
Run Code Online (Sandbox Code Playgroud)

我希望有一种方法可以通过点击向移动设备上的所有朋友发送应用请求.请分享.

Som*_*luk 5

您收到的错误消息("param ID中的所有用户必须已接受TOS")是因为您尝试将应用生成的请求发送给未连接到您的应用的用户.

请在此处查看开发人员文档.

通过请求对话框和应用生成的请求发送的请求不同,您无法使用应用生成的请求邀请用户访问您的应用.

无法通过图表API发送Facebook应用程序请求.您可以使用应用程序请求java-script对话框发送请求,您只需要在"to"属性中指定用户的ID,如文档中所述.

示例功能:

<script>
  FB.init({ appId: '**appId**', status: true, cookie: true, xfbml : true });

  function sendRequest(to) {
    FB.ui({method: 'apprequests', to: to, message: 'You should learn more about this awesome site.', data: 'tracking information for the user'});
    return false;
  }
</script>
Run Code Online (Sandbox Code Playgroud)

然后只需将每个图像的onclick连接到类似的东西 onclick="return sendRequest('**friendId**');"

你也可以在javascript中调用这个函数:它会给你所有朋友的照片.也是当前正在使用相同应用的一群朋友.您可以向其中任何人发送请求.

function sendRequestViaMultiFriendSelector() {
    FB.ui({
        method: 'apprequests',
        message: "You should learn more about this awesome site."
    });     
}
Run Code Online (Sandbox Code Playgroud)

查看Facebook好友请求 - 错误 - '所有param ID中的用户必须已接受TOS'


Shr*_*jan 0

您在developer.facebook.com 上看过“Hackbook”的演示吗?

您可以从此处参考 HACKBOOK 应用程序请求

您可以通过以下代码实现将应用程序请求仅发送给一位朋友。

代码:

Bundle params = new Bundle();

            JSONObject attachment = new JSONObject();
            JSONObject properties = new JSONObject();
            JSONObject prop1 = new JSONObject();
            JSONObject prop2 = new JSONObject();
            JSONObject media = new JSONObject();
            JSONStringer actions = null;
            try {
                attachment.put("name", "YOUR_APP");
                attachment.put("href", "http://www.google.com/");
                attachment.put("description", "ANY_TEXT");
                media.put("type", "image");
                media.put("src", "IMAGE_LINK");
                media.put("href", "http://www.google.com/");
                attachment.put("media", new JSONArray().put(media));
                prop1.put("text", "www.google.com");
                prop1.put("href", "http://www.google.com");
                properties.put("Visit our website to download the app", prop1);
               /* prop2.put("href", "http://www.google.com");
                properties.put("iTunes Link      ", prop2);*/
                attachment.put("properties", properties);
                Log.d("FACEBOOK", attachment.toString());

                actions = new JSONStringer().object()
                            .key("name").value("APP_NAME")
                            .key("link").value("http://www.google.com/").endObject();

            } catch (JSONException e) {
                e.printStackTrace();
            }

            System.out.println("ACTIONS STRING: "+actions.toString());
            System.out.println("ATTACHMENT STRING: "+attachment.toString());

            params.putString("actions", actions.toString());
            params.putString("attachment", attachment.toString()); // Original
            params.putString("to", "YOUR_FRIEND_FACEBOOK_ID");
            Utility.mFacebook.dialog(getParent(), "stream.publish", params,new PostDialogListener());



 public class PostDialogListener extends BaseDialogListener {
    @Override
    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_posted), Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_not_posted), Toast.LENGTH_SHORT).show();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果您只想将应用请求发布到一位朋友的墙上,则上述代码非常有效。如果你想在所有人上发帖,那么你必须创建 asynckTask,它为所有朋友发帖运行,并在所有墙上发布应用程序请求。

更新

这是PHP 中的链接,它完成了向所有 Facebook 好友发送请求的相同工作。

并且[这里明确解释了3,Facebook 会阻止向超过 15-20 个好友发送好友请求。

现在,您只有一个选择:在 AsyncTask 中使用上述代码将好友请求一一发送给所有好友。