Paypal GetUserinfo (Identity) only returning user_id - paypal

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.

Related

How can I get product list with its detail in rest API backend is magento2

I'm working on native mobile application backend is magento2 and I want to display product after customer selected a category. I am able to get list of the product by category in rest request but that list don't have much details about the product.
Request : http://localhost/magento2/index.php/rest/V1/categories/24/products
(24 is category ID)
Response : [{"sku":"WH01","position":1,"category_id":"24"},...]
Earlier in Magento 1.9 product list was something like
{
2: {
entity_id: "2"
type_id: "simple"
sku: "Levis Bagpack"
description: "Bagpack"
short_description: "Bagpack"
meta_keyword: null
name: "Levis Bagpack"
meta_title: null
meta_description: null
regular_price_with_tax: 45
regular_price_without_tax: 45
final_price_with_tax: 45
final_price_without_tax: 45
is_saleable: true
image_url: "http://172.16.8.24:8080/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/image.jpg"
}
What should I do to get more info about product so I can show image and other things in mobile app ?
Maybe you can try the GET /V1/products/:sku REST API to get all the details.
Link
The returned value will be a representation of \Magento\Catalog\Api\Data\ProductInterface (including the additional attributes)
Link for Reference
Check \Magento\Catalog\Api\ProductRepositoryInterface::get which services the GET /V1/products/:sku REST API.
You can make multiple requests for all product SKUs.
OR
You can use the search API to fetch the entire list in a single request based on your criteria:
For example:
http://localhost/magento2/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=simple&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Simple2&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[current_page]=1&searchCriteria[page_size]=2
In the case of products with SKUs - simple and Simple2 are being searched.
define('BASEURL','http://localhost/magento20_0407/');
$apiUser = 'testUser';
$apiPass = 'admin123';
$apiUrl = BASEURL.'index.php/rest/V1/integration/admin/token';
/*
Magento 2 REST API Authentication
*/
$data = array("username" => $apiUser, "password" => $apiPass);
$data_string = json_encode($data);
try{
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);
$token = json_decode($token);
if(isset($token->message)){
echo $token->message;
}else{
$key = $token;
}
}catch(Exception $e){
echo 'Error: '.$e->getMessage();
}
/*
Get Product By SKU REST API Magento 2
Use above key into header
*/
$headers = array("Authorization: Bearer $key");
//$requestUrl = BASEURL.'index.php/rest/V1/products/24-MB01';//24-MB01 is the sku.
//$requestUrl = BASEURL.'index.php/rest/V1/products?searchCriteria[page_size]=10';// get total 10 products
//$requestUrl = BASEURL.'index.php/rest/V1/categories/24/products';// 24 category id
$requestUrl = BASEURL.'index.php/rest/V1/products?searchCriteria=';//get all products
$ch = curl_init();
try{
$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$result = json_decode($result);
if(isset($result->message)){
echo $result->message;
}else{
print_r($result);
}
}catch(Exception $e){
echo 'Error: '.$e->getMessage();
}
Similarly you can change $requestUrl and filter product list by category id and get product detail.
Please confirm whether it solves your problem or not. Else I'll post another solution.
You can try this, where '30' is category id. http://magentohost.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&%20searchCriteria[filter_groups][0][filters][0][value]=30&%20searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[pageSize]=10
Please try to use this endpoint instead of your endpoint:
/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=24&searchCriteria[filter_groups][0][filters][0][condition_type]=eq
It is the same as #Alexander Timonchev, But you have to remove the space after &

Paypal Payment Data Transfer not working in sandbox

I'm trying to get Paypal to redirect to my website after a transaction and retrieve information about the transaction. So far, Paypal does redirect to the correct location, but the php curl operation that I make back to Paypal afterwards retrieves an error page instead of the SUCCESS/FAIL message I'm expecting:
Sorry — your last action could not be completed
[...]
We are unable to
complete your request at this time. Please click Retry or try again
later. We apologize for the inconvenience.
Message 3004
I've tried simply having my code print the 'tx' parameter on screen, building my request manually and putting it directly in the browser, ie:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-synch&tx=34A96012RS258972T&at=x7cYS4yOvBi2k_LuLWsJ3h_J-2n-29VCgzhFDR79on8s1mQSlSxIIibiW3e
But the same error page described above gets returned.
I'm logged in to my sandbox paypal account, and the 'at' parameter holds the correct payment data transfer identity token associated with my sandbox merchant test account.
Is my request missing anything? I haven't tested it with my actual Paypal account since I don't want any real money exchanges until I know it works.
same error here - noticed 2 weeks ago - have been in contact with paypal who told me to check my code - but even copied and pasted code sample still generates the error. When you log into the test seller account, can you see the transaction? I can but clicking the details view again generates the error.
I was able to pass through PDT on this account but then it suddenly started to fail with no change to my code.
UPDATED 31/07/2012:
Still no confirmed resolution from Paypal - spoke to telephone support for merchants NOT technical team asthey apparently have no tech support by phone - was told by merchant advice basically to test live and avoid sandbox. A minimum 20p per test though as you'd have to refund your test transactions.
Not a very happy man I can tell you. :(
$tx=$_REQUEST['tx'];
$paypal_url='https://www.paypal.com/cgi-bin/webscr?cmd=_notify-synch&tx='.$tx.'&at=token here';
$curl = curl_init($paypal_url);
$data = array(
"cmd" => "_notify-synch",
"tx" => $tx,
"at" => "token here"
);
$data_string = json_encode($data);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);
$headers = array (
'Content-Type: application/x-www-form-urlencoded',
'Host: www.paypal.com',
'Connection: close'
);
curl_setopt ($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
$lines = explode("\n", $response);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
$first_name=$keyarray['first_name'];
$last_name=$keyarray['last_name'];
$payment_status=$keyarray['payment_status'];
$business=$keyarray['business'];
$payer_email=$keyarray['payer_email'];
$payment_gross=$keyarray['payment_gross'];
$mc_currency=$keyarray['mc_currency'];
}

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

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.

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