Send App request to all friends in Facebook using 'Requests Dialog' in Android
Asked Answered
P

2

12

I want to know how to send app request to all my facebook friends from android app. I tried in graph API. But, couldn't get it done.

https://graph.facebook.com/apprequests?ids=friend1,friend2&message='Hi'&method=post&access_token=ACCESS_TOKEN

I know this is a Duplicate question. But, couldn't find an answer yet. I'm getting this error on the above API.

"All users in param ids must have accepted TOS."

I hope there will be a way to send app request to all friends from mobile on a click. Please share it.

Preponderant answered 16/1, 2013 at 12:44 Comment(1)
do you have any pic or sample which type of app request you want to post on friend's wall.Settee
C
6

The error message you receive ("All users in param ids must have accepted TOS") is because you are trying to send an app generated request to a user who is not connected to your app.

See the developer docs here.

Requests sent with the request dialog and app generated requests are different and you can't use app generated requests to invite users to your app.

Sending Facebook app requests are not available via the graph api. You can use the app requests java-script dialog to send the request though, you would just need to specify the user's id in the "to" property as detailed in the documentation.

Sample function:

<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>

Then just wire an onclick for each image to something like onclick="return sendRequest('**friendId**');"

Also you can call this function in javascript: It will give you all friends with photos. Also group of friends who are currently using same app. You can send request to any of them.

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

See Facebook Friend Request - Error - 'All users in param ids must have accepted TOS'

Copyread answered 21/1, 2013 at 10:18 Comment(2)
I want to send it from app.Preponderant
Then you can only send it to users who have installed your appHandicapped
S
0

Have you seen demo of "Hackbook" in the developer.facebook.com ?

You can refer HACKBOOK APP REQUEST FROM HERE.

You can achieve to post the app request to only one friend by below code.

Code:

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();
        }
    }
}

Above code works perfect if you want to post the Apprequest only on One friend's wall. If you want to post on all then you have to make asynckTask which runs for all the friends post and post App request on all walls.

Update

Here is the link in PHP that have done same work to send request to all Facebook friends.

And [here it is clearly explained3 that it is blocked by Facebook to send a Friend Request to more then 15-20 friends.

Now, you have to only one option to do it is, use above code in AsyncTask to send Friend Request to all Friends One-by-One.

Settee answered 21/1, 2013 at 5:12 Comment(9)
It will post on friends wall about the app.Preponderant
The App request must not go to wall , it must go to user's notification or App request listPreponderant
It will be on the notification.Settee
@Gunjan: It will be the post as DrawSomething app has for the User's facebook Friend.Settee
please also check the link of "HACKBOOK APP REQUEST" from my just updated answer.Settee
let us continue this discussion in chatPreponderant
@Gugan: You should have a look atleast about my answer and what i am saying. I have one readymade android app in which user can send that same app request to his/her facebook friend.Settee
And also i need to press the share button again and again to post it to all my friends. That won't suit my app.Preponderant
@Gugan: You can avoid that share button view if you want. You have to study the code for that. Anyway All the best.Settee

© 2022 - 2024 — McMap. All rights reserved.