Facebook new payer promotion not working - facebook

Facebook new payer promotion spec at https://developers.facebook.com/docs/payments/payer_promotion/#user_eligibility
says it will return 1 if user is eligible, and nothing if not.
But, this code in PHP:
$fbdata = $facebook->api('/me?fields=id,locale,third_party_id,is_eligible_promo');
returns is_eligible_promo => '1';
But when i use that query on Graph API explorer, or with JavaScript:
FB.api('/me?fields=id,locale,third_party_id,is_eligible_promo', function(response) {});
it doesn't return is_eligible_promo field.
Also, calling this payement popup:
var obj = {
method: 'fbpromotion',
display: 'popup',
package_name: 'zero_promo',
product: '---my-open-graph-currency---'
};
FB.ui(obj, function() {});
, it returns something like "Sorry, the promotion is currently unavailable.".

But when i use that query on Graph API explorer, or with JavaScript […] it doesn't return is_eligible_promo field.
I think this is an access_token issue – whether a player is eligible for a promotion depends on the individual app, I guess.
Try choosing your own app in the Graph API explorer (dropdown on the upper right), and see if then you get the same result as from within your PHP script.

It resolved that user_is_eligible depends on IP of the user requests.
Since my servers are in country A, php request from that server to facebook returned that user is eligible. But when i request same params with javascript (i'm in country B), facebook says that user is not eligible.
Fixed this by moving all checks to javascript since it depends on user location.

Related

Display something for people who like or not like our facebook page

I search a solution for the problem highlighted in this question.
Unfortunately, the accepted solution (which dates back to 21/11/2012) doesn't work anymore, as you can this in this demo.
Does someone know why?
Body
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '179378788777832',
status : true,
cookie : true,
xfbml : true
});
</script>
<div id="login">
You are not logged in to FB, Please click here to login.
</div>
<div id="container_notlike">
YOU DONT LIKE
</div>
<div id="container_like">
YOU LIKE
</div>
JS
var hideLogin = function(){
$("#login").hide();
}
var showLogin = function(){
$("#login").show();
}
var doLogin = function(){
FB.login(function(response) {
if (response.session) {
hideLogin();
checkLike(response.session.uid)
} else {
// user is not logged in
}
});
}
var checkLike = function(user_id){
var page_id = "40796308305"; //coca cola
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function(rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
$("#container_like").show();
//here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.
} else {
$("#container_notlike").show();
//and here you could get the content for a non liker in ajax...
}
});
}
$(document).ready(function(){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
hideLogin();
checkLike(response.authResponse.userID)
} else {
showLogin();
}
});
$("#login a").click(doLogin);
});
CSS
body {
width:520px;
margin:0; padding:0; border:0;
font-family: verdana;
background:url(repeat.png) repeat;
margin-bottom:10px;
}
p, h1 {width:450px; margin-left:50px; color:#FFF;}
p {font-size:11px;}
#container_notlike, #container_like, #login {
display:none
}
I search solution for hours but I didn't find anything what works.
Thank you for help.
Like Gating is not allowed anymore, that´s why it is not possible. The only reliable way to get that information is by authorizing a user with the user_likes permission and using /me/likes/[page-id]. But you will not get that permission approved for like gating in the Login Review.
People need to like something because they really want to, not because they get something for it:
Only incentivize a person to log into your app, enter a promotion on your app’s Page, or check-in at a place. Don’t incentivize other actions
Source: https://developers.facebook.com/policy/
Btw, you can also subscribe to the edge.create event to find out if a user just clicked your like button, but you can´t find out if the user liked it before: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
The problem on that code is that FQL is deprecated .
You can't do what you want to, and thats why changes are necessary .
Your code would work if your app is old, created before changes that turns like gating not allowed, but anyway, you cannot use that for show content. You can use that kind of implementation for creating an interactive experience, where you can for example changing the content, saying "Thanks for liking".. Or "Connect with us, liking our page.." ..
You can also think about interfaces, where you show up the page plugin, and just after user likes, you say Thank you ... and hide the page plugin ... But user must always be able to close without liking .
For checking if user likes a page, you need use :
FB.api get on '/me/likes', and with the response ...
if (response.data[likes].name == "Coca-Cola")
or... better
if (response.data[likes].id == "40796308305") {
}
I repeat, One thing has nothing to do with another ..
You can check if user likes a page, but you cannot restrict content, based on this kind of resource .
There are other ways to check it, for exaple :
Get api call to userid/likes/pageid returns page info if user likes the page, and returns nothing if user does not like the page .
You will waste time trying do that for controlling content consumption .
Your app must be aprooved for asking user_likes permission, and its better you think about creating another experience for users, instead of submitting something like that .
I also think that content with good open graph for sharing, commenting and optional liking is very much more efetive, because i noticed that many people used to like and dislike the page after getting the content .
If you just... Prompt a FB.UI for sharing after 1 minute, for example, you will have much more results .. Aways positioning the page plugin in strategic places, people will naturally like your page ..
Than you can say change the page plugin element :
Thank you for liking, please share with your friends ....
Who would also like ...
Or use a callback for triggering the share dialog ..
OLD SCHOOL API CALL
The method FB.Event.subscribe() allowed apps to subscribe to a range of events, and define callback functions for when they fire, is deprecated .
Also FQL Query is deprecated .
For checking if user likes a page, you need user.likes permission, so you can try :
FB.api get on '/me/likes', and with the response ...
if (response.data[likes].name == "Coca-Cola")
or... better
if (response.data[likes].id == "40796308305") { }
There are other ways to check it, for exaple :
Get api call to userid/likes/pageid returns page info if user likes the page, and returns nothing if user does not like the page .
You can check if user likes a page using this call, but you cannot restrict content, based on this kind of resource .
2018 UPDATED SOLUTION
But nowadays, in 2018 the best method for is setting Webhooks .
Webhooks are a subscription based system between Facebook and your server. Your app subscribes to receive updates from Facebook via a specified HTTPS endpoint .
This allows your to app to receive notifications whenever there are updates to a chosen set of topics and their fields, so, you can track changes to most sections of the user's profile, such as About, Photos, Posts, Friends, and Likes.
Webhooks update notifications are sent as POST requests to a callback URL that you supply. Notifications can be lightweight, indicating only that a field has been updated, or can include the newly updated value .
webhooks user reference
Full list of user profile fields that you can subscribe to, such as About, Photos, Posts, Friends, and Likes.
webhooks page reference
The easiest way to set up your app to receive Webhooks updates is to use the App Dashboard's, check out Facebook Platform documentation for more info .
Webhooks documentation

API Error Code 1383146 in Facebook Canvas API for Unity while making payment

I have implemented payments in my Unity app and have defined products in HTML form in my server, and have crawled them with FB's debug tool. The products are identical to Facebook's payments example apart from pricing and naming, as well as the photo link.
Yet, when I run FB.Canvas.Buy after deploying the app to Canvas, I get the following error:
An error occurred. Please try again later.
API Error Code: 1383146
API Error Description: invalid og type. Expected og:product, got website
This error has no documentation I can seem to find on any search engine or on Facebook's own documentation.
Any help would be appreciated, thank you.
I found the problem was I was passing the actual URL of the HTML product into the pay dialog rather than the graph object ID.
When using the graph object ID, I am finally able to perform purchases.
I meet the same error code 1383146 and found the root cause.
In the beginning i expect the product URL will be my current URL plus product.html. For example. My page is https://a.b.c/def/ and i expect FB to parse my product page https://a.b.c/def/product.html
var productURL = window.location.href + 'product.html';
var obj = {
method: 'pay',
action: 'purchaseitem',
product: productURL
};
FB.ui(obj, function(data) {
...
});
But i found FB will add query string when POST to my canvas page URL in some cases. URL will become https://a.b.c/def/?fb_source=search&ref=ts&fref=ts. Then my code will be wrong because i use window.location.href. So i update code and never meet 1383146 issue.
var productURL = window.location.protocol + "//" + window.location.host + window.location.pathname + 'product.html';
var obj = {
method: 'pay',
action: 'purchaseitem',
product: productURL
};
FB.ui(obj, function(data) {
...
});
In my case, the Facebook scraper could not reach the web server that is hosting the products (it could only be reached from our office, which I did not know). In that case, Facebook constructs a default object of type website and then complains about that.
You can see this in action with the Facebook Sharing Debugger. Enter your product URL, and hit the 'Debug' and maybe 'Scrape Again' buttons. It will show 'Warnings That Should Be Fixed'. It will only show the first warning by default, make sure you show all warnings. For me, one of those warnings further down was 'Cannot Connect To Server'. So that was the REAL problem

Facebook app - permissions varying from tester to tester

Bit of an odd one: I've created an app that uses a jQuery AJAX request to query the Graph API and access a list of a given user's Likes (someone on my Friends list). I can use this within my app, and I get the same result as if I'd run the query through the Developer tools Graph API Explorer site (https://developers.facebook.com/tools/explorer).
The fun begins when people on the Testers list for the app (which is sandboxed) perform exactly the same actions, with the same friend (who isn't on the testers list); they don't receive any data back from the Graph API at all.
The testers have granted my app all the same permissions as I have, so why would we be getting different results?
Finally - I think I've found the solution.
By switching the Facebook JavaScript SDK file to a direct link rather than an asynchronous download, and calling the FB.login function with extra permissions defined in the scope later down the page:
FB.login(function (response) {
if (response.authResponse) {
// init app here
} else {
// cancelled
}
}, { scope: 'user_likes,friends_likes' });
... the testers are able to access their friends' Likes. Phew!

Facebook JS SDK throwing 104 error when attempting to delete a app request

I have setup the facebook javascript sdk to initialize a friend invite dialog to send requests to friends. Clicking on the invite in Facebook, brings the user back to the site.
The query string has any and all request_ids that have not been handled (deleted).
I am following the documenation listed at the FB developers site here which states:
JavaScript SDK:
FB.api(requestId, 'delete', function(response) {
When they are returned to my site, the querystring has a request_ids parameter:
example: www.mysite.com/somepage?request_ids=0493834050
my Javascript code looks like this:
FB.api(requestIds[i], 'delete', function (response) {
console.log(response);
});
But the error I get is:
ERROR
code: 104
message: "An access token is required to request this resource."
type: "OAuthException"
All I want to do is delete the request ID. before I was even running the above code, the querystring was building up with every submitted request. It does appear they have been removed, because the querystring is reduced down to a single request id. But I am still uncertain it has been handled properly.
NOTE I am not using the Graph version - as I have not setup Graph on the app settings in Facebook.
I have the Facebook C# sdk - if someone has an easy way to do this here. I have tried the following with the same results.
var fbClient = new FacebookClient(accessToken)
fbClient.Delete(requestId);
I don’t see what’s possibly unclear about the error message – you need a valid access token to be able to delete requests, but by the looks of it you don’t have one.
So you’ll either have to have the user connect to your app in order to get an active access token for him; or you have to do it using your own app access token (but that’d have to be done server-side then, because you don’t want to transfer your app access token to the client side).

Prevent signups with Facebook proxy email

Problem is, when a user clicks on FB Login button on my site, Facebook API throws him with a window which ask for access permissions(which is the usual flow). But when the user chooses the proxy mail address (anonymous), then I want to force the user to login only using his real email id.
How am I supposed to handle this ?
I can detect that user used proxy email and prevent him from registering, but then I can't remove my app from his list of authorized apps - meaning I can't get him to that initial dialog for choosing which email he will provide.
You can't force the user to go through the authorization dialog again, because as far as Facebook is concerned, the user has installed your application and nothing else needs to happen. The best thing you can do here is write your own form which informs the user that the Facebook proxy e-mail address is unacceptable and you need a real e-mail address. Unfortunately, this does not force the user to give you their Facebook account e-mail address, or even a real e-mail address. This is the best we have via Facebook though, and it's just something we have to deal with.
UPDATE 5/10/11
I was browsing around the Facebook documentation, and found a method that exists in the old Legacy REST API which actually allows you to remove extended permissions for your app from a user. I think you could use this exact API call to manage getting non-proxy addresses from your Facebook user, while still using the native install dialog.
I tested this using the FB JS SDK and it worked! The method you need to use is the auth.revokeExtendedPermission method. Here are 2 examples of calling that method via the JS SDK and the PHP SDK.
Javascript:
<script>
FB.api({
method: 'auth.revokeExtendedPermission',
perm: 'read_stream'
}, function(response)
{
console.log(response)
});
</script>
PHP:
<?php
$facebook->api(array(
'method' => 'auth.revokeExtendedPermission',
'perm' => 'email',
'uid' => $uid
));
Because these use the Legacy REST API they're not as "supported" as the new Graph API. I've not seen anything regarding migrating this feature to the Graph API. Hopefully they will.
Invoke revocation of the app through graph api (as below) with the php sdk then redirect user back through your dialog with this non-proxy requirement explained.
private function revokeAccess() {
$access_token = $this->facebook->getAccessToken();
$result = $this->facebook->api(array(
'method' => 'auth.revokeAuthorization',
'uid' => $this->{facebook id here},
'access_token' => $access_token
));
return $result;
}
This code is php.
This completely removes the app.
Returns 1 on success; 0 on failure.
$this->facebook == facebook object from the facebook php sdk.