Getting 411 error bad request in Evernote - php

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.

Related

Github webhook PHP script returns "Missing HTTP 'Content-Type' header."

Some information beforehand:
I have 1 servers with 2 domains, one is the live version (live), the other is for testing purposes (redesign).
I'm using GitHub webhooks to automatically update my redesign server with the repository so that when there's multiple people working on the repo, we don't have to manually deploy it every time.
Now, I have found a PHP script (This is exactly how I use it apart from the secret) on GitHub in which the webhook is being parsed returns an error saying that the Content-Type header is missing, while when I look in the webhook delivery it clearly has the header.
The error presents itself on line 33 of the PHP script which checks if the HTTP_CONTENT_TYPE is present by checking
if (!isset($_SERVER['HTTP_CONTENT_TYPE'])) {
throw new \Exception("Missing HTTP 'Content-Type' header.");
}
To ask an actual question: How can the PHP if throw the exception when the header is clearly present?
I think the name HTTP_CONTENT_TYPE is wrong. It looks like it has been used as a fix for the bug Sets HTTP_CONTENT_TYPE but not CONTENT_TYPE.
Normally CONTENT_TYPE property should be used following the RFC 3875
I made a simple test to check how it works
Created an index.php file on my web server
echo $_SERVER['CONTENT_TYPE'].PHP_EOL;
Opened the file using cUrl
$ curl -H "Content-Type: application/json" http://localhost
The outpus for me is
application/json
HTTP_CONTENT_TYPE property is not set in my test case.

Subscribe to timeline updates - (400) callbackUrl must be a valid HTTPS URL

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.

Am i using the API V2 or V3 in this piece of code?

My live, staging and localhost had a page where it had a map and store finder.
6 months down the line this now does not work and havent touched the code. I have renewed my API key and still no luck. Now i know the API V2 is now not in use and im wondering if i am using the wrong code (confused myself). In my store finder i have this url:
$url = "http://maps.google.co.uk/maps/geo?q=".urlencode($this->input->post('postcode'))."&output=json&key=MYKEY";
Now reading this page ( https://developers.google.com/maps/documentation/geocoding/#JSON ) this has changed but i just cant seem to get a valid url working!
The error i get is: Message: file_get_contents(http://maps.google.co.uk/maps/geo?q=sr3+4as&output=json&key=MYKEY): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
And when i type the url string into google i get this message:
We're sorry...
... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.
If someone can guide me to if my url string is wrong above OR if this is another issue i would appreciate it.
Thanks!
According to the upgrade guide this endpoint URL:
http://maps.google.co.uk/maps/geo
Is using the v2 geocoding API.
Developers switching from v2 may be using a legacy hostname — either maps.google.com, or maps-api-ssl.google.com if
using SSL. You should migrate to the new hostname: maps.googleapis.com.
This URL based on the information in the update guide works for me:
http://maps.googleapis.com/maps/api/geocode/json?address=nebraska&sensor=false

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..!

Categories