PHP Sessions and Parse - php

I've a few php files that need to access the Parse backend. I don't know how to connect them. In my previous question the answer was: SESSIONS!
Now i've a new problem:
If i comment out session_start(), i've access to the Parse database, but not to the session variables.
If i uncomment session_start(), i've access to Session variables, but not to Parse anymore.
Why is that?
<?PHP
//session_start();
echo "I'm in PHP!!!";
require 'vendor/autoload.php';
use Parse\ParseException;
use Parse\ParseClient;
use Parse\ParseQuery;
use Parse\ParseUser;
ParseClient::initialize('xxxxx', 'xxxxx', 'xxxxx');
ParseClient::setServerURL('https://xxxxxx');
//if (isset($_SESSION["currentUser"])){
$query = new ParseQuery("CourseInfo");
$query -> equalTo ("CourseID", "Demo2");
$results = $query->find();
echo "Successfully retrieved " . count($results) . " scores.";
// }
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>"; // just to test
if (isset($_SESSION["currentUser"])) {echo $_SESSION["currentUser"];}
?>

After calling the initialize method, add the following:
ParseClient::setStorage( new ParseSessionStorage() );
Also checkout: http://parseplatform.github.io/docs/php/guide/#session-storage-interface

I think your answer is right, a somewhat more detailed explanation is here:
New parse.com php API - currentUser not giving back a user
Tx

Related

Trying to Get Coinbase API to work

I'm trying to figure out where I'm going wrong with the below code to work with the Coinbase API. I have Composer installed with the Coinbase dependency. Previously I was getting an error that the Coinbase class was not installed, which I figured out was because of the path. I no longer get any error but the code is not executing. Can anyone help?
<?php
require_once __DIR__ . '/usr/bin/vendor/autoload.php';
use coinbase\coinbase;
//I've tried to run it both with and without the following 3 lines of code with no difference
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$apiKey = 'XXX';
$apiSecret = 'XXX';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$account = $client->getPrimaryAccount();
echo 'Account name: ' . $account->getName() . '<br>';
echo 'Account currency: ' . $account->getCurrency() . '<br>';
?>
Per the examples on the Coinbase repository, you've got a namespacing issue. PHP can't find the Configuration or Client classes.
<?php
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
at the top of your file will resolve it. After that, read http://php.net/manual/en/language.namespaces.basics.php and http://php.net/manual/en/language.namespaces.rationale.php.

Error to integrate with QuickBooks

I'm doing an integration with PHP my system, so I can launch sales in QuickBooks. To integrate'm using the API provided this link https://github.com/consolibyte/quickbooks-php.
Set everything as instructed, but the moment you throw a sale, I get the following error:
2020: [Required param missing, need to supply the required value for the API, Required parameter Line.DetailType is missing in the request]
The class that generates invoices is currently as follows:
<?php
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/views/header.tpl.php';
?>
<pre>
<?php
$InvoiceService = new QuickBooks_IPP_Service_Invoice();
$Invoice = new QuickBooks_IPP_Object_Invoice();
$Invoice->setDocNumber('WEB' . mt_rand(0, 10000));
$Invoice->setTxnDate('2015-12-10');
$Line = new QuickBooks_IPP_Object_Line();
$Line->setDetailType('Example');
$Line->setAmount(12.95 * 2);
$Line->setDescription('Example');
$SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
$SalesItemLineDetail->setItemRef('8');
$SalesItemLineDetail->setUnitPrice(12.95);
$SalesItemLineDetail->setQty(2);
$Line->addSalesItemLineDetail($SalesItemLineDetail);
$Invoice->addLine($Line);
$Invoice->setCustomerRef('67');
if ($resp = $InvoiceService->add($Context, $realm, $Invoice))
{
print('Our new Invoice ID is: [' . $resp . ']');
}
else
{
print($InvoiceService->lastError());
}
?>
</pre>
<?php
require_once dirname(__FILE__) . '/views/footer.tpl.php';
Someone has gone through this problem?
I really need help because they do not understand much about QuickBooks.
Thanks,
This error:
Required parameter Line.DetailType is missing in the request
Means you are missing a required parameter named Line.DetailType in your request. More specifically -- in your case, you're actually sending an invalid value for this parameter.
$Line->setDetailType('Example');
That ^^^ is not valid. Please take the time to refer to Intuit's documentation:
https://developer.intuit.com/docs/api/accounting/Invoice
And take the time to refer to the examples:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_invoice_add.php#L21
And notices that the documentation/examples show the correct value is:
// Set to SalesItemLineDetailfor this type of line.
$Line->setDetailType('SalesItemLineDetail');

Error when using QuickBooks PHP DevKit examples

I have successfully setup the Quickbooks PHP DevKit, but I am currently trying to run the example_customer_add script with my sandbox. When I do, I get the following error:
Notice: Undefined variable: Context in /Applications/MAMP/htdocs/quickbooks-php/test_qb.php on line 54
I've tried to track down the $Context variable, but it is used all over the place, and I'm unsure of where it being set, etc...
Any help is appreciated! Thanks!
EDIT
I'm just using the script included in the docs folder of the Quickbooks PHP DevKit:
<?php
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/views/header.tpl.php';
?>
<pre>
<?php
$CustomerService = new QuickBooks_IPP_Service_Customer();
$Customer = new QuickBooks_IPP_Object_Customer();
$Customer->setTitle('Ms');
$Customer->setGivenName('Shannon');
$Customer->setMiddleName('B');
$Customer->setFamilyName('Palmer');
$Customer->setDisplayName('Shannon B Palmer ' . mt_rand(0, 1000));
// Terms (e.g. Net 30, etc.)
$Customer->setSalesTermRef(4);
// Phone #
$PrimaryPhone = new QuickBooks_IPP_Object_PrimaryPhone();
$PrimaryPhone->setFreeFormNumber('860-532-0089');
$Customer->setPrimaryPhone($PrimaryPhone);
// Mobile #
$Mobile = new QuickBooks_IPP_Object_Mobile();
$Mobile->setFreeFormNumber('860-532-0089');
$Customer->setMobile($Mobile);
// Fax #
$Fax = new QuickBooks_IPP_Object_Fax();
$Fax->setFreeFormNumber('860-532-0089');
$Customer->setFax($Fax);
// Bill address
$BillAddr = new QuickBooks_IPP_Object_BillAddr();
$BillAddr->setLine1('72 E Blue Grass Road');
$BillAddr->setLine2('Suite D');
$BillAddr->setCity('Mt Pleasant');
$BillAddr->setCountrySubDivisionCode('MI');
$BillAddr->setPostalCode('48858');
$Customer->setBillAddr($BillAddr);
// Email
$PrimaryEmailAddr = new QuickBooks_IPP_Object_PrimaryEmailAddr();
$Customer->setPrimaryEmailAddr($PrimaryEmailAddr);
if ($resp = $CustomerService->add($Context, $realm, $Customer))
{
print('Our new customer ID is: [' . $resp . '] (name "' . $Customer- >getDisplayName() . '")');
}
else
{
print($CustomerService->lastError($Context));
}
?>
</pre>
<?php
require_once dirname(__FILE__) . '/views/footer.tpl.php';
The quickbooks_oauth table looks like this after attempting to connect:
'1', 'DO_NOT_CHANGE_ME', '12345', 'qyprdaX1yo1uYqu3GU8xxPvs8raoTss2ZVRBE3fHWy7qZdAB', 'IWZHlW2e956sqR9GVIxa2JOU82NdSrJixZLpb3af', 'KNwiKE2bUXtqFqJ/Vb0NhjzBGYMXwRRcT9xtFOQiV6F8aEgUoqGzA7aheRLPJ/z6EPYy1ZS4e6ZuVpteBaQtxc5H0cN5VcCmWLfj+lryaCpLgw8mGK5+E/Muv2wJ+3UwbOyqVstU+pYQw/yNgFKhfSuA3lOgjgqctuO6ZpMK1wWr42IycA05QrJuOB4+LQ==', 'rCj1V3zl4Jj5mHgTw+BPCPN7SDcJkzLQPWb1tyerEXedsQB0WsZ+caMCBafS+hfN3ECZl3mfNDSyIqKDK+t8RSEAKyFWwRSPOh3UcWDCDEhXrTSUddmKhoIq6pL6yVtNEyETyNtfMaKYN+U6uIwSEMKZB/4IUjK8c0GP5KhoKSl0dv+Bp9w=', '1391140255', 'QBO', NULL, '2015-06-04 19:57:58', '2015-06-04 19:58:36', '2015-06-04 19:58:36'
The code you posted is missing several lines at the top of the script. Look at the example on GitHub:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_customer_add.php#L3
There are two require_once statements that you are missing. $Context is defined in those required files.
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/views/header.tpl.php';
Fix your code so that you're using the example code completely, and making sure those required files actually get included.
If you continue to have trouble, please post your updated code.
You can see where $Context gets defined here:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/config.php#L110
Note that you must be connected to QuickBooks to run the example. I'm assuming you have clicked the "Connect to QuickBooks" button and gotten connected already... right?

Upload Files to Sharepoint Library through WS with PHP (NTLM & ThyBag)

I use the Lists-WS from Sharepoint to retrieve information about DocumentLibraries and the files in these Libraries. Now I want to upload new files. How do I implement uploads with PHP? Till now I use Thybag SharePointAPI to get information (Link).
(the SharepointServer uses NTLM-Authentication)
THX in advance!!
UPDATE:
I want to call the Copy.asmx WS from sharepoint. To do so, I use the following lines:
$sourceurl = 'http://null';
$params = '
<CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SourceUrl>'.$sourceurl.'</SourceUrl>
<DestinationUrls>' . $destinationURLs . '</DestinationUrls>
<Stream>' . $stream . '</Stream>
</CopyIntoItems>
';
$xmlvar = new \SoapVar($params, XSD_ANYXML);
// Attempt to run operation
try {
$result = $this->soapClient->CopyIntoItems($xmlvar)->CopyIntoItemsResponse->CopyIntoItemsResult;
} catch (\SoapFault $fault) {
$this->onError($fault);
}
But I dont even get any response ($result == NULL).....
You can use SPServices' CopyIntoItems method. You can find a detailed conversation here containing the details on using the CopyIntoItems service to upload a document.

GooglePlus API - (401) Invalid Credentials error

We have code that was working perfectly to access the Googleplus Api, but now it inexplicably no longer works, instead returning a "(401) Invalid Credentials" error when this line is called:
$me = $plus->people->get('me');
Here is the full code snippet (php):
try
{
$client = new apiClient();
$client->setApplicationName("Google OAuth");
$client->setClientId(GOOGLE_API_CLIENT_ID);
$client->setClientSecret(GOOGLE_API_CLIENT_SECRET);
$client->setRedirectUri(GOOGLE_API_REDIRECT_URI);
$client->setDeveloperKey('XXX');
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
$plus = new apiPlusService($client);
$oauth2 = new apiOauth2Service($client);
$client->authenticate();
$token = $client->getAccessToken();
if (isset($token))
$client->setAccessToken($token);
if ($client->getAccessToken()) {
$me = $plus->people->get('me');
}
}
catch (Exception $x)
{
echo "Stack: " . $x->getTraceAsString() . "<br />";
echo "Message: " . $x->getMessage() . "<br />";
echo "File: " . $x->getFile() . "<br />";
echo "Line: " . $x->getLine(). "<br />";
}
I had the same error when user denied access to my aplication, and the token remained in the DB (or session). The API was trying to authenticate using old token. You need to check
if(strpos($x->getMessage(), 'Invalid Credentials')) {
unset($_SESSION['access_token'];
}
and also remove any relevant data from your db.
What fails? the first call to authorize, or the 2nd one to get the token ?
Check the URLs that are sent, it will be easier to inspect the issue.
and: Google might have changed their oAuth APIs?
Everything checks out as far as I can tell, it's possible that something went wrong with the credentials associated with your account.
To verify this, try using another account to access the API or try revoking your application from Google accounts. To revoke your application from your account:
Navigate to this page: https://www.google.com/settings/account
Click the Security link and then click the Manage access button on the bottom of the page.
Find the application that corresponds to your site and click
After your site/application is revoked, go back to your site and then re-authenticate.
This problem is caused when you login from other device using same credentials and then logout .

Categories