i want to send notification who access my app.i use following code.
but it not work.i was goggling about it.but every example looks like my one.but it not work for me.
here is my code
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'myappid',
'secret' => 'myappsecret',
));
$app_id='myappid';
$app_secret='myappsecret';
$app_access_token=$app_id.'|'.$app_secret;
$user_id='359211054272153';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$response = $facebook->api( '/359211054272153/notifications', 'POST/v2.2/', array(
'template' => 'You have received a new message.',
'href' => 'RELATIVE URL',
'access_token' => $app_access_token
) );
i am used old version of Facebook sdk it want to real user id.
but currently
Facebook gives app scoped userid. thats the error.
using new sdk v4 it not problem.
Related
I'm using FB App to publish posts to my FB pages.
So when i use this code for links, it works.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true
));
$attachment = array(
'access_token' => $row["token"],
'name' => $_POST["name"],
'picture' => $_POST["picture"],
'message' => $_POST["message"],
'link' => $_POST["link"]);
try
{
$facebook->api("/".$row['id']."/feed", "POST", $attachment);
}
catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}
But, when i want to share pictures as a page:
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
'fileUpload' => true,
'allowSignedRequest' => false
));
$attachment = array('access_token' => $row["token"], 'url' => 'http://image.link.jpg', 'message' => $_POST["message"]);
try
{
$facebook->api("/".$row['id']."/photos", "POST", $attachment);
}
catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}
The app post picture as user. USER to PAGE.
So i found that i need to use publish_pages permission, but my access token contains both publish_actions and publish_pages. I can't change that because I'm using one access token for a lot of things.
So i have to ask, is there a way to explicitly choose what permissions i want to use from access token. FB API have same code for page and user picture publish /user_id/photos and /page_id/photos.
Need to use Page access token, there's no other way.
I have to post on a facebook page, the titles of articles (with link) posted on a blog.
Unfortunately I can only post the link, but without the title. How can I do?
The PHP code I am using is this:
require ("facebook.php");
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXX',
'cookie' => true
));
// id page
$pageId = "136860079786056";
// permanent session token
$permSess = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// writing
$test = $facebook->api(array(
"uid" => $pageId,
"method" => "stream.publish",
"access_token" => $permSess,
"message" => "http://www.mysite.it/functions.php?p=view&id=31", ));
There is a link variable you can use for the link.
Eg
"link" => "http://google.com",
"message" => "The search engine we can't mention"
We are trying to get user information from getUser() method of facebook using php sdk (3.1.1) but it returns 0. what would be the cause?
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
));
$facebook->getUser();
The latest SDK is v.3.2.2 https://github.com/facebook/facebook-php-sdk/ you should use that instead and also be using a login handling logic with getLoginUrl()
how can i get the current logged in userid ?
im pretty sure my appId is correct
$facebook = new Facebook(array(
'appId' => '...',
'secret' => '...',
));
im using this method but i returns 0;
$facebook->getUser();
If you want to get facebook user id with this code
$facebook = new Facebook(array(
'appId' => 'your_app_id',
'secret' => 'your_app_secret',
));
$user = $facebook->getUser();
You have condition to should have done before, the first condition is you put that code in the page that redirected after the user login via fb provide by this code
$params = array(
'display'=>'popup',
'redirect_uri' => 'http://example.com'
);
$loginUrl = $facebook->getLoginUrl($params);
OR the second condition is you already have the user 'Access Token', so the code will be like this
$facebook = new Facebook(array(
'appId' => 'your_app_id',
'secret' => 'your_app_secret',
));
$facebook->setAccessToken('user_access_token');
$user = $facebook->getUser();
If you don't clear about the Facebook Login flow using PHP SDK, you can visit this page
$myData=$facebook->api('/me');
$myid=myData['id'];
$myName=myData['name'];
$myUsername=myData['username'];
[id] => your id
[name] => your full name
[first_name] => your firs name
[last_name] => lastname
[link] => profil link
[username] => username
[gender] => your gender (male,female)
[email] => your mail (if have email permission)
[timezone] => 2
[locale] => your locale
[verified] => 1
Follow this guide: Login for Server-side Apps. Basically, you have to generate a login URL, receive a code generated by Facebook, and with this code, request for an access token.
I have this code in php that used to work, but now it doesn't, and even thoug it sounds like a lie, I did not touch anything!
$facebook = new Facebook(array(
'appId' => 'myApp',
'secret' => 'mySecret',
'cookie' => true ,
'scope' => 'read_stream','manage_pages'
));
$user = $facebook->getUser();
if ($user!=0) {
doStaff;
}else{
$login_url = $facebook->getLoginUrl($params = array('scope' => "read_stream"));
echo ("<script> top.location.href='".$login_url."'</script>");
}
The problem now is that gets stack in an infinite loop.
Any help would be really appreciate.
You are probably using the deprecated Facebook PHP SDK.
Try to get the latest Facebook PHP SDK