Is it possible to get friend's emails using facebook api? - php

I am getting name and id but not more informations about friends.
<?php
$friends = $facebook->api('me/friends');
//print_r($friends['data']);
print_r("Number of Friends: ". count($friends['data']));
foreach ($friends['data'] as $key=>$listOfFriends)
{
echo "<br/>".$key." ".$listOfFriends['name']."<img src='https://graph.facebook.com/".$listOfFriends['id']."/picture' width='50' height='50' title='".$listOfFriends['name']."' />";
}
?>

From the Facebook docs:
"Likewise, to protect the privacy of users who have not explicitly authorized your application, your application will only be able to access the basic profile information about a user's friends, like their names and profile pictures. If your application needs to access other data about a user's friends to enable social functionality, you will need to request some of the special friends permissions listed below."

You cannot get the email address of your friends...Everything depends on their Privacy Settings.
If they have allowed to let see friends or other users to view their email address then you can retrive, otherwise NOT.

You can, but you have to ask the user for the specific email permissions.
"A user's email is a protected property and access to that information must be specifically requested by the app and granted by the user."
Here is the link https://developers.facebook.com/docs/reference/login/email-permissions/
UPDATE:
useing Facebook Javascript SDK, on client side, you can use this code to ask for email permissions:
FB.login(function(response) { // Asking for email permission.
// After getting the response, check if the user has granted the permission or not.
FB.api({ method: 'fql.query', query: 'SELECT email FROM permissions WHERE uid = ' + UserID}, function(resp) {
if(resp[0]['email'] == '1')
; // Permission given.
else
; // Permission not given.
});
}, {scope: 'email'});

Related

how to get the account information in microsoft one drive/sky drive php sdk

I am generating an application for the cloud search with integration of some cloud plateform . I am working on the microsoft sky drive . everything is fine but i need the account information means the user id and username. please help me . i am using this php sdk
function get_user() {
$response = curl_get(skydrive_base_url."/users?access_token=".$this->access_token);
if (#array_key_exists('error', $response)) {
throw new Exception($response['error']." - ".$response['description']);
exit;
} else {
return $response['link'];
}
}
You can to do a GET using a USER_ID for a particular user or me to get information about the currently signed in user
GET https://apis.live.net/v5.0/USER_ID?access_token=ACCESS_TOKEN
Or for information about the signed-in user
GET https://apis.live.net/v5.0/me?access_token=ACCESS_TOKEN
It returns user id, but not username. You also receive user name, first name, last name, gender, and locale.
Further information available here: http://msdn.microsoft.com/en-us/library/dn659736.aspx

This does not let the app post to Facebook php

I am creating a Facebook app through php. I am using the following code for users to add the app:
$config = array();
$config['appId'] = '532241193565136';
$config['secret'] = '19de17575ad3d245c8cc32f5b623e310';
$config['cookie'] = true;
$config['fileUpload'] = true; // optional
$fb = new Facebook($config);
$user = $fb->getUser();
$loginUrl = $fb->getLoginUrl(
array(
'scope' => 'publish_actions'
)
);
This should allow users to post to Facebook through the app. The problem I'm having is the Permissions popup does not allow users to select the type of Publish Permission - Public, Custom, Only Me etc. I always get This does not let the app post to Facebook
Posts are being added to the Facebook Page but obviously they are private to the user who added the post.
Not sure if I'm missing something here...
Update:
I've tried deleting the application and adding a new, did not make any difference though.
Update 2:
I've just tried using the application from an Admin User of the Page...The following permissions have not been approved for use and are not being shown to people using your app: publish_actions
Information Update:
Just in case someone stumbles on this question. Facebook's Review Guidelines states that "The review time estimate will range between 7 to 14 business days." Always important to consider these delays :)
You're missing nothing here. From v2.0 onwards, the permissions other than public_profile, email and the user_friends need to the submitted for review before you can make your app live; until then, only the testers/admin/developers of the app will be able to test app with those permissions.
Since you are the admin of your app, you can test the publishing but-
it will be visible to you or other admins/testers/developers only
you'll not see the provacy setting option because that does not makes sense
For the login submission (after your app is ready to be live) see this link.
If your submission was rejected you can post using the Feed Dialog, the Requests Dialog or the Send Dialog. Your app does not need to request the publish_actions permission for that. It's an alternative. (see the publish_actions permission reference).
function publish() {
FB.api('/<albumid>/photos', 'POST',
{"url": 'example.com/image.jpeg',
"caption": 'text'
},
function(response) {
if (!response || response.error) {
// Error trying post method - now trying a feed dialog
FB.ui({message: text,
method: 'feed',
link: 'example.com',
picture: 'example.com/image.jpeg',
caption: text,
}, function(response){
//successful feed dialog without publish_actions permission
});
} else {
//successful post with publish_actions permission
}
});
}

Can we get email ID from Twitter oauth API?

How to get email id of the user who accepted my Twitter application?
I have gone through lot of forums. But they have mentioned, it is not possible. Also those posts are older than a year. May I know whether it is possible to get the user email id through twitter API using PHP?
I am getting Twitter user details using the following URL:
https://api.twitter.com/1.1/account/verify_credentials.json
This is now possible by filling out a form to request elevated permissions:
Go to https://support.twitter.com/forms/platform
Select "I need access to special permissions"
Enter Application Name and ID. These can be obtained via https://apps.twitter.com/ -- the application ID is the numeric part in the browser's address bar after you click your app.
Permissions Request: "Email address"
Submit & wait for response
After your request is granted, an addition permission setting is added in your twitter app's "Permission" section. Go to "Additional Permissions" and just tick the checkbox for "Request email addresses from users".
Note that user e-mail address has to be verified, otherwise Twitter refuses to provide it. (See include_email parameter description in elevated permissions doc page.)
Now you can fetch user email address from twitter API and it's a lot much easier. Just follow these steps...
Goto Twitter Apps
Click on 'Create New App'
Fill all required credentials and click on 'Create your Twitter application'
Now click on 'Permissions' tab -> check 'Request email addresses from users' field and click on 'Update Settings'. (check given picture)
Now in your PHP code, set all app details and add this code!
$params = array('include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true');
$data = $connection->get('account/verify_credentials', $params); // get the data
// getting twitter user profile details
$twt_id = $data->id; //twitter user id
$twt_email = $data->email; //twitter user email
All Done.
Hope it help you, good luck. ;)
It is now possible to retrieve a user's email address from Twitter (if the user permits it, of course).
You'll need to apply to have your application white-listed to receive xAuth.
Check here for more info:
https://dev.twitter.com/rest/reference/get/account/verify_credentials
Yes you can get email address.This is now possible by filling out a some permission.
1.Go to this Link: https://apps.twitter.com/
2.After go to permission tab inside your created Application
3.Select Addition permission checkbox in your APP.
4.After successfully update setting you can get email address from Twitter.
If in some case you can not getting email address then please check your Oauth Api request url.
Your request url should be this type :https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true
It is not possible to get user's email address from twitter. You can see it here. You can open a form page on your callback page and get user's email address on that page. You can refer here for example usage
Here is how I have done this in ASP.Net using linqtoTwitter library
http://www.bigbrainintelligence.com/Post/get-users-email-address-from-twitter-oauth-ap
// call verify credentials api
var twitterCtx = new TwitterContext(authTwitter);
var verifyResponse =
await
(from acct in twitterCtx.Account
where (acct.Type == AccountType.VerifyCredentials) && (acct.IncludeEmail == true)
select acct)
.SingleOrDefaultAsync();
if (verifyResponse != null && verifyResponse.User != null)
{
User twitterUser = verifyResponse.User;
//assign email to existing authentication object
loginInfo.Email = twitterUser.Email;
}

How to get email address on facebook API

I'm developing a Facebook app and downloaded facebook-php-sdk-master file from facebook. It is working great it is just i need the email address of the people who use our app.. and it does not return the email address... i made some research and a youtube video said to request it on getLoginUrl
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$statusUrl = $facebook->getLoginStatusUrl();
$loginUrl = $facebook->getLoginUrl(array('email'=>'email'));
}
but still doest return the email address. Please help. Thanks!
That's not correct. You're requesting the permission to read the user's e-mail address. Any permission requests should be made with the scope field, like so:
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email'
));
The above code will create the URL. Now, to direct users to this URL, you can use the following code:
Login
When a user clicks on the above link, they'll be asked to supply the permission for reading their emails.
If you want additional permissions, you can request it the same way. Just add them to the scope field as comma-separated values. The full list of permissions, including defaults, can be found in the Facebook Developers documentation.

Getting user's birthday through Facebook API

I'm having some troubles with the Facebook API, I am requesting permission for some information of the user by Javascript:
FB.login(function (response) {
if (response.authResponse) {
// authorized
} else {
// canceled
}
}, {scope: 'email,user_birthday,user_location'});
Now I want to get the user's information (when he is authorized) by PHP:
$facebookUser = json_decode(file_get_contents('https://graph.facebook.com/' . $this->data['userid'] . '?access_token=' . $this->oathtoken . '&fields=id,name,location,gender,email,picture,birthday,link'));
All working great, except that the API is not giving the user's birthday back. Even when I set my birthday privacy settings on public it won't show up.
So:
echo $facebookUser['birthday']; // Gives an error, since this key does not exists
Does somebody have an idea how to fix this?
You are logged in on the client side but php is executed on the server side so you receive only the basic information of an user object.
If you logged in on the server side and have the permissions so you can get the birthday simply with:
echo $facebookUser['birthday'];
Most probably you didn't receive approval to request user_birthday from FB.
You can't get user_birthday unless FB reviews your FB app.
Only the following permissions may be requested without review: public_profile, user_friends and email
(See: https://developers.facebook.com/docs/facebook-login/review/what-is-login-review)
Without review you can request only age_range, but not user_birthday
FB.login(function (response) {
var user_birthday = response.user_birthday;
console.log(user_birthday);
if (response.authResponse) {
} else {
// canceled
}
}, {scope: 'email,user_birthday,user_location'});
why don't you use serverside auth if you would like get FB info in server side?
if you are ok with clientside authentication, above should work.

Categories