Seller Central
Seller Forums

Amazon Seller Forums » Login With Amazon » Questions about Login With Amazon

Thread: LWA using JS: Array Warning: urlencode() expects parameter 1 to be string,
Thread Archived This thread has been archived - replies are not allowed.

This question is not answered.

Permlink Replies: 1 - Pages: 1 - Last Post: 26 Apr, 2017 3:57 PM by: Anurag S. (LWA)

Posts: 1
Registered: 24 Apr, 17 5:15 PM
Posted on: 24 Apr, 2017 11:22 AM  
Click to report abuse...

I am trying to use Javascript sdk and am running my website on cloud9 server.
My client login file is labelled login.html and code posted below:


<!--- this first script loads lWA sdk for JS--->

<script type="text/javascript">

window.onAmazonLoginReady = function() {
(function(d) {
var a = d.createElement('script'); a.type = 'text/javascript';
a.async = true; = 'amazon-login-sdk';
a.src = '';


<!-- this script is for button-->

Login with Amazon

<!-- this script loads the login page on clicking the button -->

<script type "text/javascript">

document.getElementById('LoginWithAmazon').onclick = function() {
setTimeout(window.doLogin, 1);
return false;

window.doLogin = function() {
options = {};
options.scope = 'profile';
options.response_type= 'code';

amazon.Login.authorize(options, "");



On the server side, I am running my_login.php (code below):


// Verify that the access token belongs to us
// The token must be url-encoded when passed to tokeninfo

echo $_REQUEST;

$c = curl_init('' . urlencode($_REQUEST));
curl_setopt($c, CURLOPT_RETURNTRANSFER,true);

$r = curl_exec($c);
$d =json_decode($r);
echo $d;

echo $r;

echo $d;
if ($d->aud != '<client_id>') {
// the access token does not belong to us
header('HTTP/1.1 404 Not Found');
echo 'Page not found';

// Exchange the access token for user profile
// The token must NOT be url-encoded when passed to profile

$c = curl_init('');
curl_setopt($c, CURLOPT_HTTPHEADER, array('Authorization: bearer'. $_REQUEST));
curl_setopt($c, CURLOPT_RETURNTRANSFER,true);

$r = curl_exec($c);
$d =json_decode($r);

echo sprintf('%s %s %s', $d->name, $d->email,$d->user_id);


The _echo $_REQUEST;_ command says this error:

Array Warning: urlencode() expects parameter 1 to be string, array given in /home/ubuntu/workspace/my_login.php on line 8 Call Stack: 0.0015 237224 1. {main}() /home/ubuntu/workspace/my_login.php:0 0.0015 237472 2. urlencode() /home/ubuntu/workspace/my_login.php:8 Page not found

I have been following the tutorials as stated here :

It would be great, if you could help debug this issue.


Edited by: Anurag S. (LWA) on Apr 26, 2017 3:47 PM
Is this a helpful question? Yes 0   No
1 Reply
Sort replies by:
Anurag S. (LWA)

Posts: 23
Registered: 16 Oct, 14 12:50 AM
Posted on: 26 Apr, 2017 3:57 PM   in response to: vs_app in response to: vs_app  
Click to report abuse...
Thanks for reaching out.

Looking at your code snippets it seems like there is a minor syntax error on line 8.
I suggest you try changing the line 8 from something like:

$c = curl_init('' . urlencode($_REQUEST));


$c = curl_init('' . urlencode($_REQUEST));

Login With Amazon
Was this reply helpful? Yes 0   No 0