大家好我跟随本教程' QuickBooks OAuth – PHP Example'设置api并从quickbooks获取数据。我已经成功设置了api,但我现在遇到的问题是我无法从快速书籍中获取数据。它总是返回null,即使它们上面有很多数据
以下是我正在做的代码。
的config.php
<?php
// setting up session
/* note: This is not a secure way to store oAuth tokens. You should use a secure
* data sore. We use this for simplicity in this example.
*/
// session_save_path('./abc/temp');
session_save_path('./abc/temp');
session_start();
echo "<h4>If you see a Session warning above you need to run the command: 'chmod 777 temp' in the terminal on the code page. </h4>";
define('OAUTH_CONSUMER_KEY', 'some key');
define('OAUTH_CONSUMER_SECRET', 'some key');
if(strlen(OAUTH_CONSUMER_KEY) < 5 OR strlen(OAUTH_CONSUMER_SECRET) < 5 ){
echo "<h3>Set the consumer key and secret in the config.php file before you run this example</h3>";
}
?>
的index.php
<?php
require_once("./config.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Connect Page</title>
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
<script>
// Runnable uses dynamic URLs so we need to detect our current //
// URL to set the grantUrl value ########################### //
/*######*/ var parser = document.createElement('a');/*#########*/
/*######*/parser.href = document.url;/*########################*/
// end runnable specific code snipit ##########################//
intuit.ipp.anywhere.setup({
menuProxy: '',
grantUrl: 'http://'+parser.hostname+'/QuickbooksTest/oauth.php?start=t'
// outside runnable you can point directly to the oauth.php page
});
</script>
</head>
</head>
<body>
<?php
require_once('./v3-php-sdk-2.3.0/config.php'); // Default V3 PHP SDK (v2.0.1) from IPP
require_once(PATH_SDK_ROOT . 'Core/ServiceContext.php');
require_once(PATH_SDK_ROOT . 'DataService/DataService.php');
require_once(PATH_SDK_ROOT . 'PlatformService/PlatformService.php');
require_once(PATH_SDK_ROOT . 'Utility/Configuration/ConfigurationManager.php');
error_reporting(E_ERROR | E_PARSE);
// print connect to QuickBooks button to the page
echo "<ipp:connectToIntuit></ipp:connectToIntuit><br />";
// After the oauth process the oauth token and secret
// are storred in session variables.
if(!isset($_SESSION['token'])){
echo "<h3>You are not currently authenticated</h3>";
} else {
$token = unserialize($_SESSION['token']);
$requestValidator = new OAuthRequestValidator(
$token['oauth_token'], $token['oauth_token_secret'], OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
$realmId = $_SESSION['realmId'];
// uncomment any of these to see more information
//echo "realmId: $realmId <br />";
//echo "oauth token: ". $token['oauth_token'] . "<br />";
//echo "oauth secret: ". $token['oauth_token'] . "<br />";
/*echo "<pre><h2>Session Variables</h2>";
var_dump($_SESSION);
echo "</pre>"; */
$serviceType = $_SESSION['dataSource'];
$serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator);
$dataService = new DataService($serviceContext);
// $startPosition = 1;
// $maxResults = 10;
// $allCustomers = $dataService->FindAll('Customer', $startPosition, $maxResults);
$allCustomers = $dataService->Query("SELECT * FROM Customer");
echo "<pre><h2>Customers List</h2>";
var_dump($allCustomers);
echo "</pre>";
}
?>
</body>
</html>
更新的INDEx
<?php
require_once("./config.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Connect Page</title>
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
<script>
// Runnable uses dynamic URLs so we need to detect our current //
// URL to set the grantUrl value ########################### //
/*######*/ var parser = document.createElement('a');/*#########*/
/*######*/parser.href = document.url;/*########################*/
// end runnable specific code snipit ##########################//
intuit.ipp.anywhere.setup({
menuProxy: '',
grantUrl: 'http://'+parser.hostname+'/testProject/oauth.php?start=t'
// outside runnable you can point directly to the oauth.php page
});
</script>
</head>
</head>
<body>
<intuit>
<ipp>
<logger>
<!-- To enable/disable Request and Response log-->
<requestLog enableRequestResponseLogging="true" requestResponseLoggingDirectory="C:\IdsLogs" />
</logger>
</ipp>
</intuit>
<?php
require_once('./v3-php-sdk-2.3.0/config.php'); // Default V3 PHP SDK (v2.0.1) from IPP
require_once(PATH_SDK_ROOT . 'Core/ServiceContext.php');
require_once(PATH_SDK_ROOT . 'DataService/DataService.php');
require_once(PATH_SDK_ROOT . 'PlatformService/PlatformService.php');
require_once(PATH_SDK_ROOT . 'Utility/Configuration/ConfigurationManager.php');
require_once(PATH_SDK_ROOT . 'QueryFilter/QueryMessage.php');
error_reporting(E_ERROR | E_PARSE);
// print connect to QuickBooks button to the page
echo "<ipp:connectToIntuit></ipp:connectToIntuit><br />";
// After the oauth process the oauth token and secret
// are storred in session variables.
if(!isset($_SESSION['token'])){
echo "<h3>You are not currently authenticated</h3>";
} else {
$token = unserialize($_SESSION['token']);
$requestValidator = new OAuthRequestValidator(
$token['oauth_token'], $token['oauth_token_secret'], OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
$realmId = $_SESSION['realmId'];
error_log($realmId);
// uncomment any of these to see more information
//echo "realmId: $realmId <br />";
//echo "oauth token: ". $token['oauth_token'] . "<br />";
//echo "oauth secret: ". $token['oauth_token'] . "<br />";
/*echo "<pre><h2>Session Variables</h2>";
var_dump($_SESSION);
echo "</pre>"; */
// error_log("Value in dataSource session is: " . $_SESSION['dataSource']);
// $serviceType = $_SESSION['dataSource']; //5:15 PM
$serviceType = IntuitServicesType::QBO; //5:16 PM
$serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator);
$dataService = new DataService($serviceContext);
// $startPosition = 1;
// $maxResults = 10;
// $allCustomers = $dataService->FindAll('Customer', $startPosition, $maxResults);
// $allCustomers = $dataService->Query("SELECT * FROM Customer");
$allCustomers = $dataService->FindAll('Customer');
// $oneQuery = new QueryMessage();
// $oneQuery->sql = "SELECT";
// $oneQuery->entity = "Customer";
// $oneQuery->orderByClause = "FamilyName";
// Run a query
// $queryString = $oneQuery->getString();
// $allCustomers = $dataService->Query($queryString);
// $ch = curl_init("http://www.example.com/");
// $fp = fopen("example_homepage.txt", "w");
// curl_setopt($ch, CURLOPT_FILE, $fp);
// curl_setopt($ch, CURLOPT_HEADER, 0);
// curl_exec($ch);
// curl_close($ch);
// fclose($fp);
echo "<pre><h2>Customers List</h2>";
var_dump($allCustomers);
echo "</pre>";
}
?>
</body>
</html>
***的app.config *
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<intuit>
<ipp>
<!--Json serialization not supported in PHP SDK v2.0.0 -->
<message>
<request serializationFormat="Xml" compressionFormat="None"/>
<response serializationFormat="Xml" compressionFormat="None"/>
</message>
<service>
<baseUrl qbd="https://quickbooks.api.intuit.com/" qbo="https://quickbooks.api.intuit.com/" ipp="https://appcenter.intuit.com/api/" />
</service>
<logger>
<!-- To enable/disable Request and Response log-->
<requestLog enableRequestResponseLogging="true" requestResponseLoggingDirectory="./IdsLogs" />
</logger>
</ipp>
</intuit>
</configuration>