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 ;)
Related
We have three environments, Dev, QA and Prod.
We have a stable PHP running that connects with evernote , get token and fetch content.
we updated our QA environment to PHP 7.0 and now when via evernote when we try to fetch Token it returns
Invalid auth\/bad request (got a 411, expected HTTP\/1.1 20X or a redirect)
Here is the code
$oauth = new \OAuth($this->consumerKey, $this->consumerSecret);
return $oauth->getRequestToken($this->getEndpoint('oauth'), $callbackUrl);
I have checked that consumerKey etc and everything is correct.
I am not sure what error could be here since 411 is normally when you need to send content length, but in Evernote API they dont mention anything like this
Is this due to PHP 7.0 ?
Any help will be appreciated
Thanks
Yes, you probably need to send the content length.
Does Evernote change the API validation for the Content-Length?
I see there is another workaround proposed on Github.
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.
I've been working with the Mirror API, specifically the php quick start project. I'm receiving an error after attempting to subscribe to timeline updates:
An error occurred: Error calling POST https://www.googleapis.com/mirror/v1/subscriptions: (400) callbackUrl must be a valid HTTPS URL
I do have SSL enabled and working on my test server.
In the subscribe_to_notifications function on mirror-client.php (line 111) I see a reference to the callbackUrl: $subscription->setCallbackUrl($callback_url);
However, I am not able to find where to change this. Should it be set to notify.php? Can someone get me pointed in the right direction?
Found out the issue, in config.php my $base_url needed to be set to the secure version.
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..!
I am having an issue when upgrading from Facebook's PHP SDK version 2.1.2 to 3.1.1 in anticipation for the Oct 1, 2011 cutoff. The url appears to have changed:
FROM
https://www.facebook.com/login.php?api_key=MY_KEY
TO
https://www.facebook.com/dialog/oauth?client_id=MY_KEY
Everytime I generate the new URL I keep receiving "An error occurred with Website. Please try again later."
I have searched the wiki/faq on Github page for sdk, but haven't found anything.
Anyone else having this issue?
I had this exact same problem while converting a Connect application. I figured it out! Connect used the application KEY (which is alphanumeric). The new API / oAuth requires the application ID (which is shorter and numeric). An invalid application ID consistently returns this generic error. Hope this helps.
Just in case someone else has this same issue you can also try disabling sandbox mode on your app's config settings on facebook. My scenario was that I could login using facebook but no one else could.