Facebook significant_other_id - facebook

I need a little help about a PHP FB app.
Matter is that I wan't to access the significant_other_id as $relationId.
First I get the authorization by user via link:
https://www.facebook.com/dialog/permissions.request?app_id=XXX&display=page&next=XLINK&response_type=code&perms=publish_stream,user_relationships
Then after authorization in php file I try this:
<?php
include('src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'XX',
'secret' => 'XX',
'cookie' => true,
));
$user_profile = $facebook->api('/me','GET');
echo $user_profile['relationship_status']; //Prints ok, requested info
echo $user_profile['significant_other_id']; //Prints nothing
I wasn't able to get that id :S if anyone has experience on this your reply would be great.
Thanks.

According to the documentation, significant_other comes back as an object containing name and id, so try:
echo $user_profile['significant_other']['id'];

Related

Trying to post to facebook page with app but get "The user hasn't authorized the application to perform this action"

I am trying to write a script that will post an update to a facebook page timeline. I created an app and created a key for the app. I am using the code below:
require_once HOME_PATH . '/include/facebook/facebook.php';
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_APP_SECRET,
'cookie' => true,
'scope' => 'publish_stream',
));
$user_id = $facebook->getUser();
$access_token = $facebook->getAccessToken();
$attachment = array(
'access_token' => $access_token,
'message' => 'this is my message',
'name' => 'name',
'link' => ROOT_URL . $blog_data['url'] . '.htm',
'caption' => $blog_data['title'],
'description' => $blog_data['title'],
);
if ($image = get_first_image($blog_data['body'])) {
$attachment['picture'] = $image;
}
$facebook->api(FACEBOOK_BLOG_PAGE . '/feed', 'post', $attachment);
i think this key is connected to the app and not to my user, so it sounds like i would have to grant the permission within facebook, but i have seen some other posts telling me that i need to do this in code. The examples aren't very clear.
I know similar questions have been asked but i haven't seen any clear answers yet. Can anyone please clarify this?
If you want to get user_id by this piece of code: $user_id = $facebook->getUser();
The first thing you need, is to login an user through a URL returned by $facebook->getLoginUrl(array('scope' => array('perm', 'perm2'))).
Also, notice, where I put permissions, which I require. Not into the Facebook class constructor, but into the method getLoginUrl.
And lastly, for posting into a page, you need publish_actions permission (not publish_stream).

facebook graph api getUser returns 0

I create new app and try to get user
require_once 'facebook.php';
$this->fb = new Facebook(array(
'appId' => APPID,
'secret' => APPSECRET,
'cookie' => true
));
$user = $this->fb->getUser();
I am using new sdk 3.2.2. On my testing environment its work until today. But now its always returns 0.
Can anybody help me?
Just based on that code there is no login handling for example getLoginUrl(), unless the user has logged in through a login flow, $user will always be zero.

Get user's country at Facebook: getSignedRequest() results without 'user' field

Code:
$facebook = new Facebook(array(
'appId' => some_fb_app_id),
'secret' => some_fb_app_secret),
'cookie' => true,
));
$result = $facebook->getSignedRequest();
echo var_export($result,1);
Result:
array (
'algorithm' => 'HMAC-SHA256',
'code' => 'A.....l',
'issued_at' => 1354720771,
'user_id' => 'some_user_id',
)
I expect $result["user"]["country"] to be set. How can I fix this problem?
ps. by Facebook Graph API - how to get user country?
According to the facebook PHP SDK getSignedRequest() only gives you the signed request, just like the name suggests. User info is usually gotten through the Graph API, using calls like
$facebook->api('/me','GET');
which gives you the profile for the user associated with the access_token you are using.
Note that you will only ever get information that you have the permissions for, so if you haven't added a particular bit of info beyond the basics to your apps scope, you will not get it.

login from one domain and after that getting facebook object in another domain using php sdk 3.1.1

I am logining in and making the authentication processes from one domain (localhost)
$config = array(
appId' => $APP_ID,
'secret' => $APP_SECRET
);
$facebook = new Facebook($config);
$currentUserId = $facebook->getUser();
This works fine and i get an Access Token and a user id.
After that. from the browser i am making a post action to a php file on a remote domain
in the remote php i use the same code the same APP_ID and the same APP_SECRET
$config = array(
'appId' => $APP_ID,
'secret' => $APP_SECRET
);
$facebook = new Facebook($config);
$currentUserId = $facebook->getUser();
this does not! work and get $currentUserId = 0
and that is my problem
I can use (but dont want to):
$facebook->setAccessToken($at);
with the acsess token from that i got form the localhost domain it does work and i get the user id
In older sdk 2.0 I have seen this function setBaseDomain
Is there a way i can use it in 3.1.1?
here's what I do - so when you make the request to the other domain pass along the access_token when you make the API call do something like this -
$config = array(
'appId' => $APP_ID,
'secret' => $APP_SECRET
);
$facebook = new Facebook($config);
$args['access_token'] = $_POST['token'] // or $_GET[];
$me = $facebook->api('/me', 'get', $args);
print_r($me);
So what that does then is say to FB I know the request is coming from a different server, but I have a valid token, please accept this sacrifice to mark zuckerberg and let me do things. It will accept and you're free to do as you please :)

Extended Permissions on Facebook Graph API in PHP

I am trying to write an app using the most recent Facebook PHP SDK. However, any extended permissions I request are simply not requested, it always defaults to the basic request, and does not ask for any of the requested extended permissions.
Here is how I am requesting these permissions:
<?php
require_once("facebook.php");
$app_id = "xxx";
$app_secret = "xxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
if(is_null($facebook->getUser())){
$params = array(‘scope’ => ‘user_status,publish_stream,user_photos’);
header("Location:{$facebook->getLoginUrl($params)}");
exit;
}
?>
This file is included at the beginning of any page on which my app is embedded. Any ideas as to why I don't get the extended permissions I want?
Make sure you are using quotes '. It seems that you copied this example from a page or something.
if(is_null($facebook->getUser())){
$params = array('req_perms' => 'user_status,publish_stream,user_photos');
header("Location:{$facebook->getLoginUrl($params)}");
exit;
}
UPDATE: use scope instead of req_perms with the new SDK.
You should pass the 'scope' parameter in a comma separated array.