Google Calendar API with a Service Account Problems - php

I've been trying for days to get Google's Calendar PHP API working on my local Laravel development site. Here's the problem:
I'm using a service account so I can perform functions on one calendar (the service accounts calendar). I'm not authenticating users and requesting access to their calendar.
I've verified everything from my client ID, the service email address, the key.P12 file, still nothing happens.
Here is my code:
$key = File::get($this->key);
$credentialObj = new \Google_Auth_AssertionCredentials(
$this->serviceAccountName,
array('https://www.googleapis.com/auth/calendar'),
$key,
'notasecret'
);
$client = new \Google_Client();
$client->setApplicationName($this->applicationName);
$client->setClientId($this->clientId);
$client->setAssertionCredentials($credentialObj);
\session_start();
$calendarServiceObj = new \Google_Service_Calendar($client);
$events = $calendarServiceObj->events->listEvents('mygmail#gmail.com');
dd($events->getItems());
I've even tried using Google's own example here:
https://github.com/google/google-api-php-client/blob/master/examples/service-account.php
No errors, nothing. Just a blank error page every single time. I've tried so many examples all over the internet, even here on stack overflow, and at the end, all I get is a 'This webpage is not available'. This happens on every browser.
Laravel is set to development mode so all errors are displayed, and I've even force set the ini using ini_set("display_errors", 1);.
I know everything works fine up until I request anything from the service object. All the calendar api's are set to on in my developer account. Does my local development domain need to have SSL enabled?
It be so nice if I could figure out at least what is going on, but with this obscure error, I have no idea.
If anyone has any tips, I'd really appreciate it. Thanks!!
EDIT: I've scoured through googles API code, and this is exactly where the request fails:
vendor\google\apiclient\src\Google\Signer\P12.php
Line 77 to 92:
public function sign($data)
{
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
throw new Google_Auth_Exception(
"PHP 5.3.0 or higher is required to use service accounts."
);
}
$hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
//If I die(); here, I receive the response
if (!openssl_sign($data, $signature, $this->privateKey, $hash)) {
//Something happens here, or inside the openssl_sign command, I never reach the exception
throw new Google_Auth_Exception("Unable to sign data");
}
//It never reaches here
return $signature;
}
In my PHP Info:

Solved by updating PHP. I was using Softaculous AMPPs 2.3 with PHP 5.4.27. Upgrading to AMPPs 2.6 fixed the issue. My Open SSL in my config is now:
Nothing was done to my code above since, and it now works. This was definitely an open ssl issue. Anyone receiving an ERR_CONNECTION_RESET must update their open_ssl version.
I hope this helps anyone trying to figure this out.

Related

Issue understanding CouchBase connection with PHP

I just installed CouchBase and the .dll files for XAMPP. I am following their example on how to connect: "Hello Couchbase" https://developer.couchbase.com/documentation/server/current/sdk/php/start-using-sdk.html
This code:
$bucketName = "default";
// Connect to Couchbase Server
$cluster = new CouchbaseCluster("couchbase://127.0.0.1");
$bucket = $cluster->openBucket($bucketName);
gives me:
LCB_AUTH_ERROR: Authentication failed. You may have provided an invalid username/password combination
I have a fresh installation, and following their guide #1, what am I doing wrong? I don't remember setting a password, I went to the CouchBase admin page and I can't find a way to change any password.
I sympathize here -- I'm having the same error (and no, it's not you, the docs have been neglected). Instantiating the CouchbaseCluster doesn't throw the error, it's actually the openBucket() method that causes problems, and for me, the problem was that the bucket didn't exist (it would be nice if the Couchbase error were in the right ballpark instead of bumbling around in irrelevant confusion). Here's some code that worked for me:
$cluster = new CouchbaseCluster('http://127.0.0.1:8091');
$manager = $cluster->manager('MYUSER', 'MYPASSWORD');
$manager->createBucket('new_bucket');
This does throw some errors:
[cb,WARN] (htconfig L:130 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming terse URI not supported on cluster
[cb,EROR] (htconfig L:122 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming bucket does not exist as we've tried both URL types
[cb,EROR] (htconfig L:142 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got non-success HTTP status code 404
But it does work. The Couchbase forums are a better place for these types of questions -- they respond pretty quickly over there.

PHP code working locally but not on Azure

I've implemented a mail delivery service using SparkPost for a website. The code looks like this:
require '/vendor/autoload.php';
use SparkPost\SparkPost; use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
$httpAdapter = new Guzzle6HttpAdapter(new Client());
$sparky = new SparkPost($httpAdapter, ['key'=>'...']);
[...]
[...]
$results = $sparky->transmission->send($mailarray);
It works just fine locally on WampServer, however when I deploy it to Azure it does not. I don't have access to Azure logs, but I managed to narrow down the problem to one line:
$sparky = new SparkPost($httpAdapter, ['key'=>'...']);
I simply get a 500 error without any other explanation. The weird thing is when I wrap it around a try/catch, I still don't get anything other than a blank screen and a 500 on the console. I suspect it has to do something with /autoload.php not being able to load something.
Any thoughts?
According the requirement of SparkPost lib on Github repo at https://github.com/SparkPost/php-sparkpost/blob/master/composer.json#L18, it need PHP version higher than 5.5. So you can modify the PHP version of your Azure Web Apps, please refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-change-the-built-in-php-version for detail steps.

Evernote oAuth error php

I'm having issues getting an access token from Evernote using oAuth in my codeigniter app.
I am able to successfully get my temporary credentials but when I ask for my access token. I get the following error.
"Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)"
$_SESSION['requestToken'] = $requestTokenInfo['oauth_token'];
$_SESSION['requestTokenSecret'] = $requestTokenInfo['oauth_token_secret'];
$_SESSION['oauthVerifier'] = $_GET['oauth_verifier'];
print_r($_SESSION);
$accessToken = $client->getAccessToken($_SESSION['requestToken'], $_SESSION['requestTokenSecret'], $_SESSION['oauthVerifier']);
The print_r function correctly prints out the 3 parameters returned to me by Evernote as the temporary credentials.
I am using php 5.4.9 on an Ubuntu 12 server. I have installed the Pecl OAuth extension. Thank you very much in advance for any help.
To check if everything is working well, you should use their sample application.
To do so, clone the github repository you mentionned earlier, then edit the sample/oauth/config.php file by filling the variables :
define('OAUTH_CONSUMER_KEY', 'your key');
define('OAUTH_CONSUMER_SECRET', 'your secret');
// Replace this value with FALSE to use Evernote's production server
define('SANDBOX', TRUE);
then go to http://your.domain.com/evernote-sdk-php/sample/oauth/index.php to test your settings and follow the steps that appears. At the end of the test you should have a list of all your notebook, or Error before it.
Once everything is done you can have a look at the code they provide as an example to understand how the PHP code works.
hope this help as this did the trick for me with python ;)

Twitter OAuth failing to work (PHP)

I have the TwitterOAuth class and demonstration running on a local development server and I cannot get it to authorize. I have entered the new CONSUMER_KEY and CONSUMER_SECRET in the config.php. I have also synced the server time to NTP. I get the error message: 'Could not connect to Twitter. Refresh the page or try again later.'
var_dump($connection->http_code);
results:
int 0
ANY help or advise would be appreciated.
I am running PHP 5.3
When I try to ping the api server I can't.
C:\Users\Owner>ping api.twitter.com
Ping request could not find host api.twitter.com. Please check the name and try
again.
could this be the problem ?
I had some issues with this process as well. I don't exactly recall what resolved this error, but I followed This Tutorial (albeit a bit out of date) and made sure I explicitly set the callback URL in the twitter panel for my app. Also, and I believe this one also caused the int 0 return for me, make sure that if you are going with a hosting provider they allow CURL requests.
step 1: https://apps.twitter.com/app or go to your app setting
step 2: Unchecked the (Enable Callback Locking (It is recommended to enable callback locking to ensure apps cannot overwrite the callback url)) This box..
save and exit and check..
ThankYou..!

Zend_OpenId_Consumer login function hangs - even in the sample code

I've been trying to get a simple OpenId log-in working using first php-openId (Jain) and then the ZendFramework, and in both cases I run up against a similar problem. I'm using the example Zend code from step 38.2.2 of http://framework.zend.com/manual/en/zend.openid.consumer.html.
I see the log-in page fine, but when I enter my openId, this code executes:
if (isset($_POST['openid_action']) &&
$_POST['openid_action'] == "login" &&
!empty($_POST['openid_identifier'])) {
echo "New consumer";
$consumer = new Zend_OpenId_Consumer();
echo "Gotim";
if (!$consumer->login($_POST['openid_identifier'])) {
$status = "OpenID login failed.";
echo "Failure";
}
echo "Continuing";
The code seemingly hangs on the function call to $consumer->login. I see the output from my first two echos, but I never see either Failure or Continuing (and without the echos I just get a 500 Server Internal Error when I try to log-in). If I enter an invalid openId then I get the correct "OpenID login failed." error message.
I apologize if I'm being a moron here. I'm a former programmer who got promoted to management, and I'm trying to get back into it - but I'm using a bunch of technologies that are new to me (PHP, OpenID, Zend Framework), and this just isn't making any sense right now.
Does anyone have any ideas where to look? I can't believe that the Framework itself is bugged (especially not when I had a similar problem with the Jain openId stuff also). I'm using fatcow.com for web hosting - not sure if that's relevant.
Your code seems to be failing when trying to make the external HTTP connection to the OpenID provider. This could be caused by a number of things, but here's a couple suggestions:
Perhaps you're behind a proxy?
If not that, maybe your current host does not allow contacting remote servers using sockets (the url_fopen ini directive). The default adapter for Zend_Http_Client is its socket adapter.
So, I would recommend trying is to pass a Zend_Http_Client instance using a different adapter to your Zend_OpenId_Consumer class using the setHttpClient method.
There are a couple different client adapters available:
Zend_Http_Client_Adapter_Socket (default)
Zend_Http_Client_Adapter_Proxy
Zend_Http_Client_Adapter_Test
Zend_Http_Client_Adapter_Curl
Try something like this:
$client = new Zend_Http_Client(null, array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
'proxy_host' => 'example.com',
'proxy_port' => 8000,
'proxy_user' => 'user',
'proxy_pass' => 'pass'
));
$consumer = new Zend_OpenId_Consumer();
$consumer->setHttpClient($client);
Your ISP should have documentation about their proxy, if this is in fact the issue.
If proxying is not your problem, try the curl adapter and see if you have any more luck.
I still don't really understand what's wrong, but I tried running the same code on a different web host (x10hosting.com) and my sample code worked immediately. Therefore I have to conclude that this is some kind of limitation of the Fatcow webhosting service, which is rather a shame. I guess I'll be changing hosts.
If you are getting a 500 error, there is definitely a more detailed message in the web server logs. If your server is running apache, then it is most likely under /usr/local/apache/logs/error_log or /etc/httpd/logs/error_log or something similar. I am assuming you are on a shared hosting plan, so you won't have access to these. You should contact your webhosting company, as they will be able to look through the logs for you.

Categories