Next: Post to Multiple Facebook Groups

Post to Multiple Facebook Groups




If you post to multiple facebook Group you can use the following script.

Attention because it is consider SPAM !!!



1:  <!DOCTYPE html>  
2:  <html>  
3:  <head>  
4:  <title>Post to Multiple Facebook Groups</title>  
5:  <meta charset="UTF-8">  
6:  </head>  
7:  <body>  
8:  <script>  
9:    // This is called with the results from from FB.getLoginStatus().  
10:    function statusChangeCallback(response) {  
11:      console.log('statusChangeCallback');  
12:      console.log(response);  
13:      // The response object is returned with a status field that lets the  
14:      // app know the current login status of the person.  
15:      // Full docs on the response object can be found in the documentation  
16:      // for FB.getLoginStatus().  
17:      if (response.status === 'connected') {  
18:        // Logged into your app and Facebook.  
19:        testAPI();  
20:      } else if (response.status === 'not_authorized') {  
21:        // The person is logged into Facebook, but not your app.  
22:        document.getElementById('status').innerHTML = 'Please log ' +  
23:          'into this app.';  
24:      } else {  
25:        // The person is not logged into Facebook, so we're not sure if  
26:        // they are logged into this app or not.  
27:        document.getElementById('status').innerHTML = 'Please log ' +  
28:          'into Facebook.';  
29:      }  
30:    }  
31:    
32:    // This function is called when someone finishes with the Login  
33:    // Button. See the onlogin handler attached to it in the sample  
34:    // code below.  
35:    function checkLoginState() {  
36:      FB.getLoginStatus(function(response) {  
37:        statusChangeCallback(response);  
38:      });  
39:    }  
40:    
41:    window.fbAsyncInit = function() {  
42:      FB.init({  
43:        appId: '592526310889199',  
44:        cookie: true, // enable cookies to allow the server to access   
45:        // the session  
46:        xfbml: true, // parse social plugins on this page  
47:        version: 'v2.3' // use version 2.1  
48:      });  
49:    
50:      // Now that we've initialized the JavaScript SDK, we call   
51:      // FB.getLoginStatus(). This function gets the state of the  
52:      // person visiting this page and can return one of three states to  
53:      // the callback you provide. They can be:  
54:      //  
55:      // 1. Logged into your app ('connected')  
56:      // 2. Logged into Facebook, but not your app ('not_authorized')  
57:      // 3. Not logged into Facebook and can't tell if they are logged into  
58:      //  your app or not.  
59:      //  
60:      // These three cases are handled in the callback function.  
61:    
62:      FB.getLoginStatus(function(response) {  
63:        statusChangeCallback(response);  
64:      });  
65:    
66:    };  
67:    
68:    // Load the SDK asynchronously  
69:    (function(d, s, id) {  
70:      var js, fjs = d.getElementsByTagName(s)[0];  
71:      if (d.getElementById(id)) return;  
72:      js = d.createElement(s);  
73:      js.id = id;  
74:      js.src = "//connect.facebook.net/en_US/sdk.js";  
75:      fjs.parentNode.insertBefore(js, fjs);  
76:    }(document, 'script', 'facebook-jssdk'));  
77:    
78:    // Here we run a very simple test of the Graph API after login is  
79:    // successful. See statusChangeCallback() for when this call is made.  
80:    function testAPI() {  
81:      console.log('Welcome! Fetching your information.... ');  
82:      FB.api('/me', function(response) {  
83:        console.log('Successful login for: ' + response.name);  
84:        document.getElementById('status').innerHTML =  
85:          'Thanks for logging in, ' + response.name + '!';  
86:      });  
87:    }  
88:    
89:    // This function reads your Facebook groups.  
90:    function getMyGroups() {  
91:      FB.api('/me/groups?limit=900', function(response) {  
92:        var groupList = document.getElementById('groups');  
93:        response.data.forEach(function(group) {  
94:          var opt = document.createElement("option");  
95:          opt.value = group.id;  
96:          opt.innerHTML = group.name;  
97:          groupList.appendChild(opt);  
98:        });  
99:      }, {  
100:        scope: 'user_groups,publish_actions'  
101:      });  
102:    }  
103:    
104:    function postToSelectedGroups() {  
105:      var groupList = document.getElementById('groups');  
106:    
107:      var selectedGroupIds = [];  
108:      for (var i = 0; i < groupList.length; i++) {  
109:        if (groupList[i].selected) {  
110:          selectedGroupIds.push(groupList[i].value);  
111:        }  
112:      }      
113:    
114:      var delay = parseInt(document.getElementById("delay").value, 10);  
115:    
116:      function postOrFinish() {  
117:        if (selectedGroupIds.length > 0) {  
118:          var groupId = selectedGroupIds.pop();  
119:          var message = document.getElementById("message").value;  
120:          var link = document.getElementById("link").value;  
121:          FB.api(  
122:            "/" + groupId + "/feed",  
123:            "POST", {  
124:              "message": message,  
125:              "link": link  
126:            },  
127:            function(response) {  
128:              if (response.error) {  
129:                console.log(response.error);  
130:              }  
131:              setTimeout(postOrFinish, delay * 1000);  
132:            });  
133:        } else {  
134:          alert('All done!');  
135:        }  
136:      }  
137:    
138:      postOrFinish();  
139:    }  
140:  </script>  
141:  <!--  
142:    Below we include the Login Button social plugin. This button uses  
143:    the JavaScript SDK to present a graphical Login button that triggers  
144:    the FB.login() function when clicked.  
145:    -->  
146:  <fb:login-button scope="public_profile,email,user_groups,publish_actions" onlogin="checkLoginState();"></fb:login-button>  
147:  <div id="status"></div>  
148:  <br>  
149:  <label for="message">Message</label>  
150:  <textarea rows="3" placeholder="Type your message here." id="message"></textarea>  
151:  <br>  
152:  <label for="link">Link</label>  
153:  <input type="text" value="" id="link" placeholder="Your link goes here." />  
154:  <br>  
155:  <button type="button" onclick="getMyGroups();">Load Groups</button>  
156:  <label for="groups">Select your groups</label>  
157:  <select style="height: 400px;" multiple id="groups"></select>  
158:  <br>  
159:  <label for="link">Delay (number of second between requests)</label>  
160:  <input type="text" id="delay" />  
161:  <br>  
162:  <button type="button" onclick="postToSelectedGroups();">Post to Groups</button>  
163:  <br>  
164:  </body>  
165:  </html>  

In the line 43 you have replace your web App Facebook and you have to enable the url where the file is it.