Reputation: 41
Product I am working on: Requestly - Chrome and Firefox Extension Setup redirects, modify headers, switch hosts, insert user scripts (https://www.requestly.in/)
What I am trying to do: Requestly offers free 30 days access to GOLD Plan if user completes a set of few steps. One of such steps is to follow us on Twitter. I want to verify if the user has actually followed us on Twitter.
//After loading widgets.js
function followIntent (intentEvent) {
console.log("User Followed")
};
twttr.ready(function (twttr) {
twttr.events.bind('follow', followIntent);
});
Problem: The "followIntent" function is getting triggered as soon as user clicks the Follow button. I want it to be called only after user has successfully followed us. How can I achieve this?
Upvotes: 0
Views: 85
Reputation: 76
Assuming you're running into a problem that the follow
event occurs in between the events of user clicking the "following" button and the actual "following" happens. You can always call the Twitter API to verify it via GET followers/ids
. Though it seems a bit unnecessary...
function followIntent (intentEvent) {
if (!intentEvent) return;
followerVerification(intentEvent.data.user_id);
};
async function followerVerification (userID) {
// make your API request here
var userList = await twitterAPIRequest();
if (userList.includes(userID)){
console.log("User Followed")
} else {
console.log("User Not Followed")
}
}
function twitterAPIRequest() {
var settings = {
"async": true,
"url": "https://api.twitter.com/1.1/followers/ids.json?screen_name=twitterdev",
"method": "GET",
"headers": {
// Your app autherization stuff
}
}
$.ajax(settings).done(function (response) {
return response.ids;
});
}
twttr.ready(function (twttr) {
twttr.events.bind('follow', followIntent);
});
Upvotes: 1