First off: I'm using https://github.com/consolibyte/quickbooks-php
I accidentally disconnected the APP from the "Apps" page in an attempt to reconnect (get new auth creds), but it appears that was a mistake.
So now I'm trying to go through the authorization process again but I'm getting an error when I click the "Connect to QuickBooks" button on the "docs/example_app_ipp_v3/" page as described in the Quick-Start guide.
Is there something I'm missing here? I can still query through the API explorer, but I can't seem to get any data back when I use $InvoiceService->query in the code (just returns false).
//get invoice info
require_once '../includes/quickbooks-php/config.php';
// Set up the IPP instance
$IPP = new QuickBooks_IPP($dsn);
// Get our OAuth credentials from the database
$creds = $IntuitAnywhere->load($the_username, $the_tenant);
//error_reporting(0);
//ini_set('display_errors', 1);
// Tell the framework to load some data from the OAuth store
$IPP->authMode(
QuickBooks_IPP::AUTHMODE_OAUTH,
$the_username,
$creds);
// This is our current realm
$realm = $creds['qb_realm'];
// Load the OAuth information from the database
if ($Context = $IPP->context())
{
// Set the IPP version to v3
$IPP->version(QuickBooks_IPP_IDS::VERSION_3);
$CustomerService = new QuickBooks_IPP_Service_Customer();
$InvoiceService = new QuickBooks_IPP_Service_Invoice();
$ItemService = new QuickBooks_IPP_Service_Item();
$PaymentService = new QuickBooks_IPP_Service_Payment();
$invoice_query = $InvoiceService->query($Context, $realm, "SELECT *, Line.* FROM Invoice WHERE Id = '" .QuickBooks_IPP_IDS::usableIDType($main_invoice['qb_invoice_id']). "'");
$this_invoice = array();
var_dump($invoice_query);
if (count($invoice_query)){
foreach ($invoice_query as $Invoice){
//do stuff with invoice here
}
}
}
I'm getting bool(false) from the var_dump($invoice_query) even though it gets through the if($Context = $IPP->context())
Then when I visit the "docs/example_app_ipp_v3/" page with nothing but the config updated to my current auth credentials the "Connect to Quickbooks" button (html below) takes me to the 404 page.
<ipp:connecttointuit>Connect with QuickBooks</ipp:connecttointuit>
Are you POSITIVE that your App Token and other credentials are correct in the config.php file? If they are sandbox/dev tokens, please post the config file.
Are you POSITIVE that the URLs in your configuration file are correct? If they are sandbox/dev, please post them.
Is $sandbox set to TRUE or FALSE? Does that correspond to the tokens you're using?
Related
I implemented Google OAuth2 for user login on my website.
It works but after 1 hour token expires and login fails.
I read on the web that I need to get the Refresh Token (for Facebook Login I used a Long Lived Token), but code I tried doesn't work.
Here the code:
//LOGIN CALLBACK FROM GOOGLE
$gClient = new Google_Client();
$gClient->setApplicationName(SITE_TITLE);
$gClient->setClientId(get_option('google_api_id')->value);
$gClient->setClientSecret(get_option('google_api_secret')->value);
$gClient->addScope('profile');
$gClient->addScope('email');
$gClient->setRedirectUri(SITE_URL."/login/google/google-callback.php");
if(isset($_GET['code'])) {
$gClient->setAccessType('offline');
$token = $gClient->fetchAccessTokenWithAuthCode($_GET['code']);
$gClient->setAccessToken($token['access_token']);
$_SESSION['google_access_token'] = $token['access_token'];
}
if($gClient->getAccessToken()) {
// Get user profile data from google
$google_oauthV2 = new Google_Service_Oauth2($gClient);
$gpUserProfile = $google_oauthV2->userinfo->get();
}
...
This first snippet works fine.
In this second snipped, when user change page, I verify if login is still active:
$gClient = new Google_Client();
$gClient->setApplicationName(SITE_TITLE);
$gClient->setClientId(get_option('google_api_id')->value);
$gClient->setClientSecret(get_option('google_api_secret')->value);
$gClient->addScope('profile');
$gClient->addScope('email');
$gClient->setAccessType('offline');
$gClient->setAccessToken($_SESSION['google_access_token']);
if($gClient->getAccessToken()) {
if ($gClient->isAccessTokenExpired()) {
$gClient->fetchAccessTokenWithRefreshToken($gClient->getRefreshToken());
}
$google_oauthV2 = new Google_Service_Oauth2($gClient);
$gpUserProfile = $google_oauthV2->userinfo->get();
...
}
This second snipped doesn't work, because method fetchAccessTokenWithRefreshToken($gClient->getRefreshToken()) fails because $gClient->getRefreshToken() is NULL.
I debugged the callback and I saw that $token = $gClient->fetchAccessTokenWithAuthCode returns an array without "refresh_token" field.
Can anyone help me?
Thanks
Bye
I am using the Quickbooks PHP DevKit from github.com/consolibyte/quickbooks-php
Am getting the following error page after clicking on Connect to Quickbooks icon:
Notice: Undefined index: oauth_token in
/srv/disk14/2290833/www/qbstream.scienceontheweb.net/QuickBooks/IPP/IntuitAnywhere.php
on line 468
Notice: Undefined index: oauth_token_secret in
/srv/disk14/2290833/www/qbstream.scienceontheweb.net/QuickBooks/IPP/IntuitAnywhere.php
on line 468
Notice: Undefined index: oauth_token in
/srv/disk14/2290833/www/qbstream.scienceontheweb.net/QuickBooks/IPP/IntuitAnywhere.php
on line 485
Warning: Cannot modify header information - headers already sent by
(output started at
/srv/disk14/2290833/www/qbstream.scienceontheweb.net/QuickBooks/IPP/IntuitAnywhere.php:468)
in
/srv/disk14/2290833/www/qbstream.scienceontheweb.net/QuickBooks/IPP/IntuitAnywhere.php
on line 443
I added some print statements to index.php to show that the SQL database is connecting and storing variables from my edited config.php:
http://qbstream.scienceontheweb.net/docs/partner_platform/example_app_ipp_v3/index.php
mcrypt php extension is installed, you can run phpinfo.php at the above url
Attached are my development keys and development settings at developer.intuit.com (pic of settings appended to keys as I am allowed only 2 links in this post):
dev keys & settings
Here is my config.php
<?php
/**
* Intuit Partner Platform configuration variables
*
* See the scripts that use these variables for more details.
*
* #package QuickBooks
* #subpackage Documentation
*/
// Turn on some error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Require the library code
require_once dirname(__FILE__) . '/../../../QuickBooks.php';
//require_once('/home/www/qbstream.scienceontheweb.net/QuickBooks.php');
// Your application token (Intuit will give you this when you register an Intuit Anywhere app)
$token = '99cbe16bba521b4f25b99cbb4ad297910a33';
// Your OAuth consumer key and secret (Intuit will give you both of these when you register an Intuit app)
//
// IMPORTANT:
// To pass your tech review with Intuit, you'll have to AES encrypt these and
// store them somewhere safe.
//
// The OAuth request/access tokens will be encrypted and stored for you by the
// PHP DevKit IntuitAnywhere classes automatically.
$oauth_consumer_key = 'qyprdq1tdxuG9uvFFY4dQnNWtrA8a3';
$oauth_consumer_secret = 'qKK95MELeifFxcxuy7zeApvtncRcQfYtmYS9TCHi';
// If you're using DEVELOPMENT TOKENS, you MUST USE SANDBOX MODE!!! If you're in PRODUCTION, then DO NOT use sandbox.
$sandbox = true; // When you're using development tokens
//$sandbox = false; // When you're using production tokens
// This is the URL of your OAuth auth handler page
//$quickbooks_oauth_url = 'http://quickbooks.v3.com:8888/quickbooks-php/docs/partner_platform/example_app_ipp_v3/oauth.php';
$quickbooks_oauth_url = 'http://qbstream.scienceontheweb.net/docs/partner_platform/example_app_ipp_v3/oauth.php';
// This is the URL to forward the user to after they have connected to IPP/IDS via OAuth
//$quickbooks_success_url = 'http://quickbooks.v3.com:8888/quickbooks-php/docs/partner_platform/example_app_ipp_v3/success.php';
$quickbooks_success_url = 'http://qbstream.scienceontheweb.net/docs/partner_platform/example_app_ipp_v3/success.php';
// This is the menu URL script
//$quickbooks_menu_url = 'http://quickbooks.v3.com:8888/quickbooks-php/docs/partner_platform/example_app_ipp_v3/menu.php';
$quickbooks_menu_url = 'http://qbstream.scienceontheweb.net/docs/partner_platform/example_app_ipp_v3/menu.php';
// This is a database connection string that will be used to store the OAuth credentials
// $dsn = 'pgsql://username:password#hostname/database';
// $dsn = 'mysql://username:password#hostname/database';
$dsn = mysqli_connect("etc,etc,etc,etc");
// You should set this to an encryption key specific to your app
$encryption_key = 'bcde1234';
// Do not change this unless you really know what you're doing!!! 99% of apps will not require a change to this.
$the_username = 'DO_NOT_CHANGE_ME';
// The tenant that user is accessing within your own app
$the_tenant = 12345;
// Initialize the database tables for storing OAuth information
if (!QuickBooks_Utilities::initialized($dsn))
{
// Initialize creates the neccessary database schema for queueing up requests and logging
QuickBooks_Utilities::initialize($dsn);
}
// Instantiate our Intuit Anywhere auth handler
//
// The parameters passed to the constructor are:
// $dsn
// $oauth_consumer_key Intuit will give this to you when you create a new Intuit Anywhere application at AppCenter.Intuit.com
// $oauth_consumer_secret Intuit will give this to you too
// $this_url This is the full URL (e.g. http://path/to/this/file.php) of THIS SCRIPT
// $that_url After the user authenticates, they will be forwarded to this URL
//
$IntuitAnywhere = new QuickBooks_IPP_IntuitAnywhere($dsn, $encryption_key, $oauth_consumer_key, $oauth_consumer_secret, $quickbooks_oauth_url, $quickbooks_success_url);
// Are they connected to QuickBooks right now?
if ($IntuitAnywhere->check($the_username, $the_tenant) and
$IntuitAnywhere->test($the_username, $the_tenant))
{
// Yes, they are
$quickbooks_is_connected = true;
// Set up the IPP instance
$IPP = new QuickBooks_IPP($dsn);
// Get our OAuth credentials from the database
$creds = $IntuitAnywhere->load($the_username, $the_tenant);
// Tell the framework to load some data from the OAuth store
$IPP->authMode(
QuickBooks_IPP::AUTHMODE_OAUTH,
$the_username,
$creds);
if ($sandbox)
{
// Turn on sandbox mode/URLs
$IPP->sandbox(true);
}
// Print the credentials we're using
//print_r($creds);
// This is our current realm
$realm = $creds['qb_realm'];
// Load the OAuth information from the database
$Context = $IPP->context();
// Get some company info
$CompanyInfoService = new QuickBooks_IPP_Service_CompanyInfo();
$quickbooks_CompanyInfo = $CompanyInfoService->get($Context, $realm);
}
else
{
// No, they are not
$quickbooks_is_connected = false;
}
Please help me connect to intuit. Thank you.
I am using gdata to add contacts to my gmail account using the Contact API. When I run the code on my development box as localhost, everything works fine. But when I move the code to a production server (www.somedomain.com) I get "ERROR:Authentication with Google failed. Reason: BadAuthentication".
Here's my code:
<?php
// load Zend Gdata libraries
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
// set credentials for ClientLogin authentication
$user = "something#gmail.com";
$pass = "somepassword";
try {
// perform login and set protocol version to 3.0
$client = Zend_Gdata_ClientLogin::getHttpClient(
$user, $pass, 'cp');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
// create new entry
$doc = new DOMDocument();
$doc->formatOutput = true;
$entry = $doc->createElement('atom:entry');
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,
'xmlns:atom', 'http://www.w3.org/2005/Atom');
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,
'xmlns:gd', 'http://schemas.google.com/g/2005');
$entry->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
$entry->setAttribute('xmlns:gd', 'http://schemas.google.com/g/2005');
$entry->setAttribute('xmlns:gContact', 'http://schemas.google.com/contact/2008');
$doc->appendChild($entry);
// add name element
$name = $doc->createElement('gd:name');
$entry->appendChild($name);
$fullName = $doc->createElement('gd:fullName', 'Jack Frost');
$name->appendChild($fullName);
// add email element
$email = $doc->createElement('gd:email');
$email->setAttribute('address' ,'jack.frost#example.com');
$email->setAttribute('rel' ,'http://schemas.google.com/g/2005#home');
$entry->appendChild($email);
// add org name element
$org = $doc->createElement('gd:organization');
$org->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
$entry->appendChild($org);
$orgName = $doc->createElement('gd:orgName', 'Winter Inc.');
$org->appendChild($orgName);
//add to Friends list
$group = $doc->createElement('gContact:groupMembershipInfo');
$group->setAttribute('deleted' ,'false');
$group->setAttribute('href' ,'http://www.google.com/m8/feeds/groups/' .urlencode($user) . '/base/[groupid]');
//addd to my contacts
$entry->appendChild($group);
$group = $doc->createElement('gContact:groupMembershipInfo');
$group->setAttribute('deleted' ,'false');
$group->setAttribute('href' ,'http://www.google.com/m8/feeds/groups/' .urlencode($user) . '/base/6'); //adds to Friends
$entry->appendChild($group);
// insert entry
$entryResult = $gdata->insertEntry($doc->saveXML(),
'http://www.google.com/m8/feeds/contacts/default/full');
echo '<h2>Add Contact</h2>';
echo 'The ID of the new entry is: ' . $entryResult->id;
echo 'The link is: ".$entryResult->getLink('edit')."";
} catch (Exception $e) {
die('ERROR:' . $e->getMessage());
}
?>
Should I be using OAuth for Services instead? I haven't been able to find documentation on how to do this with Zend Gdata.
EDIT - ANSWER FOUND:
Ok - I still have a question about a better auth method but I figured out what the issue was in this case. Google was suspicious of my application logging in. When I checked gmail, I had received the following:
Hi Info,
Someone recently used your password to try to sign in to your Google Account [someone]#gmail.com. This person was using an application such as an email client or mobile device.
We prevented the sign-in attempt in case this was a hijacker trying to access your account. Please review the details of the sign-in attempt:
Saturday, November 2, 2013 9:43:52 PM UTC
IP Address: [xxx.xxx.xx.xxx] ([xxx.xxx.xx.xxx].unifiedlayer.com.)
Location: Unknown
If you do not recognize this sign-in attempt, someone else might be trying to access your account. You should sign in to your account and reset your password immediately.
Reset password
If this was you, and you are having trouble accessing your account, complete the troubleshooting steps listed at http://support.google.com/mail?p=client_login
Sincerely,
The Google Accounts team
I went into gmail security (through the link provided) and was able to authorize the app. Problem solved. Works perfectly now.
I'd still like some pointers on how to use my Client ID, Service Account and Private Key with Zend (if possible). I have connected using the Google API php library but I can't see how to use this within the Zend framework.
On my side, I solved the problem by entering my full email address as username (username#gmail.com).
Previously, I tried to access to my account only with the username...
Hi I'm making an app which post tweets to users time lines after they have authenticated. I'm using the library and tutorial found here : twitteroauth
Everything works fine until I get to the callback url and attempt to retrieve the access token and a var dump of the request returns Invalid request token .
here's the code :
function authenicateApp() {
//Set app keys
// Connect to twitter and recive token
$connection = new TwitterOAuth('**', '**');
$temporary_credentials = $connection->getRequestToken('http://abc.def.com');
// Redirect to twitter authentation page
header('location:'.$connection->getAuthorizeURL($temporary_credentials));
}
function appPost() {
$connection1 = new TwitterOAuth('**' ,'**', $_SESSION['oauth_token'],
$_SESSION['oauth_token_secret']);
var_dump($connection1->getAccessToken($_REQUEST['oauth_verifier']));
}
You have to actually have $temporary_credentials to the session before you try and use the session when you create $connection1.
I'm trying to get some info of my Google Analytics account using PHP. I already followed the steps for creating a Service Account in the Google Console API in this answer. I'm using the Google API Client for PHP.
This is the code I've got so far:
<?php
$path_to_src = 'src';
// These files are in /src, upload its contents to your web server
require_once $path_to_src . '/Google_Client.php';
require_once $path_to_src . '/contrib/Google_AnalyticsService.php';
$path_to_keyfile = '***'; //my private key
// Initialise the Google Client object
$client = new Google_Client();
// Your 'Product name'
$client->setApplicationName('My App Name');
$client->setAssertionCredentials(
new Google_AssertionCredentials(
'**', //gserviceaccount mail
array('https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents($path_to_keyfile)
)
);
// Get this from the Google Console, API Access page
$client->setClientId('***'); // my cliente ID
$client->setAccessType('offline_access');
$analytics = new Google_AnalyticsService($client);
// create service and get data
$service = new Google_AnalyticsService($client);
// We have finished setting up the connection,
// now get some data and output the number of visits this week.
// Your analytics profile id. (Admin -> Profile Settings -> Profile ID)
$analytics_id = 'ga:****'; // my profile id
$lastWeek = date('Y-m-d', strtotime('-1 week'));
$today = date('Y-m-d');
try {
$results = $analytics->data_ga->get($analytics_id,
$lastWeek,
$today,'ga:visits');
echo '<b>Number of visits this week:</b> ';
echo $results['totalsForAllResults']['ga:visits'];
} catch(Exception $e) {
echo 'There was an error : - ' . $e->getMessage();
}
I've enabled the openssl extension in PHP:
When browsing to the location of the php script, I just get a almost forever loading and the following error:
I'm using PHP 5.4.7:
After debuging the Google API Client code, it looks like the script is breaking at this line:
if (!openssl_sign($data, $signature, $this->privateKey, "sha256"))
Anything below this line does not get called. Looks like the error happens in this line. Is there a incompatibility here, or something?
One thing for starters you should change:
You instantiate the AnalyticsService twice. Take out the one you're not using:
$service = new Google_AnalyticsService($client);
See if that helps your problem at all.