Login on facebook using username and password. Is there any way to do that? - facebook

I have a mobile application where I want the user to send to the server his facebook credentials infos and the server will act in behalf of him in facebook (get friends list and so on).
I am researching about it, but I only find information about this oauth2, where the user logs himself in Facebook in a special link, so my app can access his FB information. This doesn't help me because I would like to access this information on the server side, not by the app itself. Is there any way that I can log in using username and password?
I have a WP7 application for facebook chat where I enter my username and password and I connect, so it should be some way to perform it, correct?
edit
Because it is against the TOS, I am thinking about doing the following:
My server sends to my client the URL so the user can login and allow my app to access its informations. After that, my server accesses it.
Would that be possible?

FB is removing the offline_access token.
No solution for this question i guess.
No offline_access, token expires in 60days, No access with username and password(AGAINST TOS)

This is against their tos, but you could use
<?php
/* EDIT EMAIL AND PASSWORD */
$EMAIL = "";
$PASSWORD = "";
function cURL($url, $header=NULL, $cookie=NULL, $p=NULL)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($p) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
$result = curl_exec($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
curl_close($ch);
}
$a = cURL("https://login.facebook.com/login.php?login_attempt=1",true,null,"email=$EMAIL&pass=$PASSWORD");
preg_match('%Set-Cookie: ([^;]+);%',$a,$b);
$c = cURL("https://login.facebook.com/login.php?login_attempt=1",true,$b[1],"email=$EMAIL&pass=$PASSWORD");
preg_match_all('%Set-Cookie: ([^;]+);%',$c,$d);
for($i=0;$i<count($d[0]);$i++)
$cookie.=$d[1][$i].";";
/*
NOW TO JUST OPEN ANOTHER URL EDIT THE FIRST ARGUMENT OF THE FOLLOWING FUNCTION.
TO SEND SOME DATA EDIT THE LAST ARGUMENT.
*/
echo cURL("http://www.facebook.com/",null,$cookie,null);
?>
http://www.daniweb.com/web-development/php/code/290893

A solution you could use that is TOS friendly would be to have the user sign up on your website and grant the offline_access token using the Facebook SDK. Your mobile app could use that token to make requests on behalf of the user in you mobile app. I would be clear as your requesting the permission with what you intend to with it.

Related

Paypal GetUserinfo (Identity) only returning user_id

I am using PHP to get user information from paypal identity API, but unfortunately i only get user_id in response. I need email and payer_id in response. I have read the documentation , according to that i am supposed to receive multiple parameters in response, but i am receiving only user_id. I have enabled all the scopes in App permissions. here is the documentation getuserinfo.
here is my code to get user info (I am passing $access_token into this function). I am using sandbox credentials.
$api_url = 'https://api.sandbox.paypal.com/v1/oauth2/token/userinfo?schema=openid';//sandbox
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token, 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = json_decode(curl_exec($ch), true);
//dd($data);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == 200)
return $data;
else if($http_code == 404)
return false;
else
return false;
my response :
array:1 [▼ "user_id" => "https://www.paypal.com/webapps/auth/identity/user/HdoaS1nMgR_Ltt5mBTv4mRvC9P1wUrWt2NlOVH2e_3w"]
This is most likely your issue: "The attributes returned depend on the scopes configured for the REST app"
https://developer.paypal.com/docs/integration/paypal-here/sandbox-testing/configuring-accounts/#create-a-rest-application
Log In with PayPal. When you enable Log In with PayPal, click Advanced Options and select Personal Information and Address Information, which are disabled by default.

Need a solution to implement xmpp add friends in group chat and sending message to them in once in php

I am Working on chat application from server side where one to one and group chat are the modules.
I am able to create the new room for the group chat.
But i am unable to invite the friends to that group using php code.
if somebody has sample code that would be great..
I write below code for sending invitation to user for that group but it is not working for sending invitation to user and it also not throw any kind of Exception.As above i have describe i am working on chat application in which i have to send invitation so that device side developer can used this invitation and call the web api for refreshing the list automatically.
<?php
$url = "http://host:port/plugins/mucservice/message?servicename=conference";
$data = "
<message from='9879870000spalchat#canopus-pc(e.g.senderjid)' to='3698000000spalchat#canopus-pc(e.g.receiverjid)'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<invite from='yorkvillecommunityschoolspalchat#conference.canopus-pc(e.g.groupjid)'/>
</x>
</message>
";
$username = "xxxx";
$password = "xxxxx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, "9090");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml',
'Authorization: Basic ' . base64_encode("$username:$password")));
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $code;
$res = curl_exec($ch);
//echo "code " . $code;
echo $res;
print_r($res);
curl_close($ch);
I have done R&D for this and then i have find out it is done by muc service Plugin.

Post to Facebook wall with script, with automatic login

I'm able to post to my Facebook wall page when logged in using a PHP script (and the Graph API). I have a news page on my main website, and would like to push news items out to Facebook as they are posted to my site (which I guess is backwards from how many people use the API).
I've granted offline_access and publish_stream to my FB account, for the FB application.
If I close my FB session and try to post from my news page, Facebook presents a login page. I've granted access, so I don't know what else I'm missing.
If I understand your question correctly, I think I have just solved the same problem. I could not solve it entirely using the graph API, but a combination of the graph api and legacy rest api did the trick. Once you have granted permission for your app to post to your facebook page wall, the following code should do what you want:
$url = "https://graph.facebook.com/oauth/access_token";
$client_id = "XXXXXXXXXXXXXX";
$client_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$postString = "client_id=$client_id&client_secret=$client_secret&type=client_cred";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$token = curl_exec($curl);
curl_close($curl);
$message = rawurlencode($description.'. Notes:'.$notes);
$url = "https://api.facebook.com/method/stream.publish";
$postString = "message=$message&uid=XXXXXXXXXXXXX&$token";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
curl_close($curl);
Few things worth noting.
1. The uid in the rest api $postString is the uid for your facebook PAGE. You do not need a target_id because when the uid is of a page it can only publish to itself.
2. Your $message must be rawurlencoded because that is the form accepted by the rest api.
3. This will post to your page as your APP, not as the user who made the post to your website. To do that you would need to have the publish_stream permission from all of your users.
Hope this helps.

Using Facebook Graph API from a mobile application

I have a small card game at Facebook (and few Russian social networks), which gets user's id, first name and avatar through the old REST API.
Now I'm trying to develop the same game as a mobile app with Flex Hero SDK for Android and iPhone. Which means I can't use native SDKs for those platforms, but have to use OAuth as descibed at Facebook page.
I'm trying to write a short PHP script, which would return the user information as XML to my mobile app. My script can get the token already:
<?php
define('FB_API_ID', 'XXX');
define('FB_AUTH_SECRET', 'XXX');
$code = #$_GET['code'];
# this is just a link for me, for development puposes
if (!isset($code)) {
$str = 'https://graph.facebook.com/oauth/authorize?client_id=' . FB_API_ID .
'&redirect_uri=http://preferans.de/facebook/mobile.php&display=touch';
print "<html><body>$str</body></html>";
exit();
}
$req = 'https://graph.facebook.com/oauth/access_token?client_id=' . FB_API_ID .
'&redirect_uri=http://preferans.de/facebook/mobile.php&client_secret=' . FB_AUTH_SECRET .
'&code=' . $code;
$ch = curl_init($req);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($ch);
if (curl_errno($ch))
exit('Download failed');
curl_close($ch);
parse_str($page, $data);
#header('Content-Type: text/xml; charset=utf-8');
#print('<?xml version="1.0"? ><app>');
print_r($data);
#print('</app>');
?>
This works well and I get back the token:
Array
(
[access_token] => 262578703638|2.OwBuoa2fT5Zp_yo2hFUadA__.3600.1294904800-587287941|ycUNaHVxa_8mvenB9JB1FH3DcAA
[expires] => 6697
)
But how can I use this token now to find the user's name and avatar and especially I'm confused by how will I get the current user id?
While using REST API I've always known the current user id by calling $userid=$fb->require_login()
See docs at: http://developers.facebook.com/docs/api
Use curl to request: https://graph.facebook.com/me/?access_token=XXXXXXX
The "/me" will get you all of the info you need.
$req = 'https://graph.facebook.com/me/?access_token=' . $access_token;
$ch = curl_init($req);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($ch);
if (curl_errno($ch))
exit('Download failed');
curl_close($ch);
$user_object = json_decode($page);
var_dump($user_object);
Will return something like:
object(stdClass)#1 (20) {
["id"]=>
string(10) "1017193642"
["name"]=>
string(19) "Lance Scott Rushing"
["first_name"]=>
string(5) "Lance"
["middle_name"]=>
string(5) "Scott"
["last_name"]=>
string(7) "Rushing"
["link"]=>
string(36) "http://www.facebook.com/LanceRushing"
.....
Since I cannot add comments I'll answer here.
In order to get the profile picture you need to request https://graph.facebook.com/ID/picture. If you want only specific fields you can specify it this way: https://graph.facebook.com/ID?fields=uid,name,etc&access_token=token
Alternatively you can use the PHP SDK to authorise and log in the user so that you don't have to get the token manually - it would simplify your code. For instance, instead of every cURL request you could just do $facebook->api(request); A good description and example are here http://apps.facebook.com/graphapidemo/.

User must have accepted TOS - Facebook Graph API error when posting photos to group page

I've been struggling to upload an image from the user's computer and posted to our group page using the Facebook Graph API. I was able to send a post request to facebook with the image however, I'm getting this error back: ERROR: (#200) User must have accepted TOS. To some extent, I don't believe that I need the user to authorize himself as the photo is being uploaded to our group page. This below, is the code i'm using:
if($albumId != null) {
$args = array(
'message' => $description
);
$args[basename($photoPath)] = '#' . realpath($photoPath);
$ch = curl_init();
$url = 'https://graph.facebook.com/'.$albumId.'/photos?'.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
$photoId = json_decode($data, true);
if(isset($photoId['error'])) die('ERROR: '.$photoId['error']['message']);
$temp = explode('.', sprintf('%f', $photoId['id']));
$photoId = $temp[0];
return $photoId;
}
Can somebody tell me if I need to request extra permissions from the user or what i'm doing wrong?
Thanks very much!
Actually, I never succeeded in this :(. As a work around, we created a new facebook user instead of a group page.
This is a known bug and it looks like they're working on it:
http://bugs.developers.facebook.net/show_bug.cgi?id=11254