I've been reading through the facebook developer docs and i'm a little confused, I want to re-engage a load of users that have gone a little stale really by giving them a little nudge regarding their inactivity on our app...
What is the current "best practice/latest way" of doing this, it seems to be via the notifications API?
https://developers.facebook.com/docs/app_notifications/#imp
If i'm correct can someone give me a couple of pointers for a PHP implementation of this, essentially it would be a cron running once a month/every two weeks wizzing through users who haven't logged in for a while and prodding them.
Thanks
Marc
Well since nobody responded to this heres a simple working solution that I figured out from the docs. To notify a user they have to authorised your app.
$book = new Facebook((array(
'appId' => 'XXXXXX',
'secret' => 'XXXXXX',
'grant_type' => 'client_credentials')
));
$vars = array(
"access_token" => $book->getAppId().'|'.$book->getApiSecret(),
"href" => "index.php",
"template" => "Some text to send up to 180 characters",
"ref" => "This is what shows up in insights so you can track responses"
);
$post = $book->api('/' . $userid . '/notifications/', 'post', $vars);
You can insert user names into template by surrounding the facebook user id with {} ie:
"{12345} would like to play some game with you." . It will throw an exception though if the uid refers to a user that hasn't authed your app.
Href automatically gets your canvas url inserted infront of it so no need to full domain/path.
ref is used in the insights interface so you can see which notifications are generating traffic!
Thats it, very simple to re-engage those users who seem to have disappeared!
Cheers
Marc
Related
I'm posting here due to a problem with php and the sdk of facebook.
For a reason I don't really know, when I try to get the userID of the logged account, continuously I received the same value, 0, even if i'm logged.
I've been trying to debug some variables, $facebook, checking sessions, etc. but with unsuccessfully results, then i'm gonna step by detailing all what i'm doing and the debug log i'm doing:
I'm using hostinger servers, that hosts my website. Due to i've found many problems, i've created a test webpage in which i have 5 files:
index.php
callback.php
facebook.php (comes from facebook)
base_facebook.php
certificate
The code i have on index.php is what i've pasted here: [index.php]: http://pastebin.com/Mfdkxz8H This is only the first part of the code which tries to get the autentification.
The code i have on callback.php is what i've pasted here: [callback.php]: http://pastebin.com/Uw0A3NM8. There i try to get the userID.
I've read some post and for some reasons there were so many cases in which the token
wasn't received in the second file/call.
I don't really know what the problem is and would be happy to find a solution.
P.D It doesn't matter the appId and secret because facebook and webpage were created for a test.
Hard to tell what is going up from your code example (By the way, you should NEVER post your appId and secret in public like that otherwise someone will be able to compromise your application). A gave your code a quick glance and it "looks" fine but here are a couple of pointers:
But here are a couple of pointers.
1) Make sure you have the latest version of the Facebook SDK (assuming you do)
2) For SANITY sake, i would keep your Facebook API files in its their folder ('sdk')
3) DOUBLE CHECK your app settings to make sure the appID and secret are correct (I have made this mistake many times), also make sure that your at is NOT in sandbox mode
4) Then try something like this
include_once("sdk/facebook.php");
//Call Facebook API
$facebook = new Facebook(array(
'appId' => XXXXXXXXXXXXXXXX,
'secret' => XXXXXXXXXXXXXXXX,
'cookie' => true, // enable optional cookie support
));
$params = array(
'scope' => 'email',
'redirect_uri' => 'http://devstarlight.esy.es/facebook/callback.php'
);
$login_url = $facebook->getLoginUrl($params);
I've recently migrated our site to Amazon EC2 from another host. On the old server, our Facebook login worked fine, but it's failing on EC2. I've done some digging, and it looks like it's failing because no value is being passed back from Facebook for the signed_request variable. I've done print_r($_REQUEST) on my return page, and the only things Facebook is passing back is code and state, in the URL itself. Nothing in POST.
I did notice that the site URL defined in my app didn't have a slash at the end, which seems to be problematic based on some comments in this forum, but that didn't help. Other answers were from a couple of years ago, and seemed to be obsolete since I couldn't find what they were referring to.
I also tried adding my EC2 IP to my app's whitelist, and that didn't help either.
Here's my current code:
if(!session_start())session_start();
require_once("facebook.php");
require_once("config.php");
$facebook = new Facebook(array(
'appId' => constant("FB_CONSUMER_KEY"),
'secret' => constant("FB_CONSUMER_SECRET"),
'cookie' => false
));
$FbId = intval($facebook->getUser());
if($FbId != 0) {
...
} else {
// log in to FB
$login_url = $facebook->getLoginUrl(array(
'scope' => 'email,user_likes,publish_stream',
'next' => '<return_page>',
'cancel_url' => '<cancel_page>'
));
exit;
}
$FbId keeps coming back with a 0 value, even after logging into Facebook. Some digging showed that this is because the user is never being set in the getUserFromAvailableData function because $_REQUEST['signed_request'] doesn't have a value.
I've tried this both already logged into Facebook and not logged in, but $_REQUEST['signed_request'] isn't returned in either case.
I've seen some posts on here that indicate that old Facebook apps seem to have some kind of grandfathering where they continue to work until they get migrated, or another new app just like it gets created. Could that be the case here?
Any help would be appreciated.
Thanks,
I have recently noticed that facebook has started ignoring my og:image tag on my site. The image used is always larger than 200x200.
Here is an example page:
http://bit.ly/15CrOhS
http://bit.ly/1b8Mgbe
Seems to be alot of questions, but no answers. I've added all the og information and checked with the linter and it all goes through fine. So why does it choose to pick a random image?
I use the facebook api for PHP to send:
<?php
$link = 'http://www.mylinkaddress.com';
$msg = 'Check out my new photo. '.$link;
$get_oauth = "SELECT * FROM users_oauth_cred WHERE userid = ".$_SESSION['userid']." AND share = 1 AND oauth_access_token != ''";
$get_oauth = mysql_query_run($get_oauth);
$oauth = mysql_fetch_array($get_oauth);
# FACEBOOK
$facebook = new Facebook(array(
'appId' => FACEBOOKAPPID,
'secret' => FACEBOOKSECRET,
'cookie' => false,
));
$token = $oauth['oauth_access_token'];
try {
$result = $facebook->api(
'/me/feed/',
'post',
array('access_token' => $token, 'message' => str_replace($link,'',$msg), 'link' => $link)
);
}
catch(FacebookApiException $e) {}
?>
I had the same issue.
Go to Facebook Object Debugger, verify every issue pointed there, fix them all. This solved my problem.
http://goo.gl/ASBsAa
Testing your query with the facebook Graph API Explorer worked fine for me.
You could try to add the additional parameter 'picture' to your post and place the link to your image in it.
So facebook is forced to use this as image in the post.
$result = $facebook->api(
'/me/feed/',
'post',
array('access_token' => $token, 'message' => str_replace($link,'',$msg), 'link' => $link, 'picture' => 'http://images.ephotozine.com/gallery/2011/49/normal/52194_1323334048.jpg')
);
Reading through all the comments here, I think what's happened is the following.
Let me know how close I got. This is a shot in the dark. ;)
The first time you shared a URL to Facebook, the og:image wasn't set up perfectly, and Facebook selected a random image on the page, and cached it.
You then fixed the og:image tag, and tried to check the same URL.. FB then regurgitated the cached image.
I tried with both your links just now, and everything seems fine.
:{D
Just be patient. Facebook needs some time to crawl this image. It will not immediately show up in Facebook. If your image is not showing up in some days, just drop a note here.
Much testing and trying other bulk uploaders etc. Finally just decided to email facebook with details and screnshot. next day the issue has been resolved. So, make sure to try that from the help email through your facebook account. worked for me.
I must be missing something really obvious.
I have created successfully an Event with the graph API
I now want to put a link on the event page
When i use the code below, it creates a message but not a link. So please someone what am i missing. I do get a linkid back as well as you can see the message on the page.
So this is the pretty simple code.
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
'fileUpload' => true
));
$fb->setAccessToken($_SESSION[ $eid.'_FB_USER_ACCESSCODE' ]);
$data = array( 'access_token' => $_SESSION[ $eid.'_FB_USER_ACCESSCODE' ],
'link' => 'http://www.thedomain.com',
'message' => "To purchase your tickets"
);
$result = $fb->api($newFBEventId."/feed","post",$data);
Thanks
This is a Bug and its reported and marked as confidential
With the below text and its also contain security hole
bug report link
Below is my bug report text.
Other details on this report are shown to Facebook employees only
I recently attempted to post on an event's wall using the Graph API, but only the message is posted; Everything else is not showing. e.g.
Link
Picture
etc
There is one more big thing that the post doesn't show; That this post is post "via a Facebook app"
Note: posting on a page or user wall worked and also normal messages posted on an event 's wall.
The most important thing is when the post is shown on the event's wall "it does not show that its posted by a Facebook Application".
This is very dangerous; For example I can make an application and post nonsense on a user's event wall. People will think that this is posted by the user.
Thanks
I'm struggling to get to grips with posting a feed item to all the members of an approved application.
Within the application settings for the user it is stating that the application has permission to post to the wall but I can only achieve this if that user is currently logged in to facebook. Obviously I would like this to function so that any items I uploaded are posted to all the members of the application at any one time.
I am using the Facebook PHP SDK from http://github.com/facebook/php-sdk/ and currrently my code is as follows:
require 'src/facebook.php';
//Generates access token for this transaction
$accessToken = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=MyAppId&client_secret=MySecret");
//Gets the full user details as an object
$contents = json_decode(file_get_contents("https://graph.facebook.com/SomeUserId?scope=publish_stream&" . $accessToken));
print_r($contents);
if ($facebook->api('/' . $contents->id . '/feed', 'POST',
array(
'title' => 'New and Improved, etc - 12/03/2010',
'link' => 'http://www.ib3.co.uk/news/2010/03/12/new-and-improved--etc',
'picture' => 'http://www.ib3.co.uk/userfiles/image/etc-booking.jpg',
'scope' => 'publish_stream'
)
)==TRUE) {
echo "message posted";
} else {
echo "message failed";
}
The output from $contents shows the expected user details but nothing relating to the permissions for my application. Am I missing a trick here?
Then using the $facebook->api() function I am receiving a
200 - Permissions error
. The application does not have permission to perform this action.
This is driving me a little potty as I suspect I'm missing something straightforward with the authorisation but what?
Many thanks in advance for an assistance offered.
I had the same problem yesterday. Finally I figured out that, although I had set checked the "permission to post to wall", I had to do this step also:
https://graph.facebook.com/oauth/authorize?client_id=XXXXXXX&scope=publish_stream&redirect=http://back.to.your.app/
There, the end-user will be served with the familiar Facebook "Allow this application to access your information?" dialog. After allowing, it will come back to your app, which then will have the proper permissions.
Hope this helps!