"Could not authenticate you." -error when using Twitter OAuth - oauth

I'm building my first system using Twitters OAuth and have some issues.
First, I'm using Abraham's Twitter-class for this and I have followed this tutorial. However, I get these lines on my callback.php:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\xampp\htdocs\twitter\twitterOAuth\OAuth.php on line 301
Warning: strtoupper() expects parameter 1 to be string, array given in C:\xampp\htdocs\twitter\twitterOAuth\OAuth.php on line 373
Oops - an error has occurred.
SimpleXMLElement Object
(
[request] => /account/verify_credentials.xml
[error] => Could not authenticate you.
)
Is this problem by Twitter-class, or am I doing something wrong? I have my Consumer Key and Consumer Secret in config.php as tutorial says, but should I store something else?
Martti Laine

The Snipe.net tutorial is for an older version of TwitterOAuth. Make sure you read the new documentation
http://github.com/abraham/twitteroauth/blob/master/DOCUMENTATION
In general updating to the new version is changing:
$content = $to->OAuthRequest('https://twitter.com/account/verify_credentials.xml', array(), 'GET');
to:
$content = $to->get('account/verify_credentials');

I was having the same error, caused by a simple mistake:
Doesn’t work:
$this->twitteroauth->post('statuses/update’, $message);
Works: $this->twitteroauth->post('statuses/update', array("status" => $message));

Related

ask util generate-lwa-tokens is no longer available?

I'm getting started on Alexa Skill MAnagement SMAPI, so I need to get a refresh token. In the documentation it is specified that 'ask util generate-lwa-tokens' should be used, but in the current version 2.0 of 'ask' this option is no longer available. Thus, I obtained access tokens using postman as described here:
https://gist.github.com/marcelobern/fe44cee1dd5ed624e03b690a447e47fd
But when running some example of smapi what I get is a server error. The example and the error:
from ask_smapi_sdk import StandardSmapiClientBuilder
smapi_client_builder = StandardSmapiClientBuilder(client_id='***',
client_secret='***',
refresh_token='***')
smapi_client = smapi_client_builder.client()
try:
result = smapi_client.list_skills_for_vendor_v1(vendor_id='***', full_response=True)
print("==========================================")
print(result.headers)
print(result.body)
print("==========================================")
except Exception as e:
print(e.body if hasattr(e, 'body') else e)
The error:
{'error_description': 'The server encountered an internal error trying to '
'fulfill the request',
'error_type': 'ServerError'}`
Thank you,
Fernando
This command is now added in the ask-cli v2.1.0, you can check the changelog at
https://github.com/alexa/ask-cli/blob/develop/CHANGELOG.md#210-2020-04-16
Solved. You have to be sure to use a refresh token since access token will throw a server exception

Twilio - Could not decode response body as JSON. This likely indicates a 500 server error

I am using Twilio Rest API to pull some usage logs
foreach ($client->account->usage_records->last_month as $record) {
if ($record->count > 0) {
$call_record[] = array(
'category' => $record->category,
'count' => $record->count,
'usage' => $record->usage,
'price'=>$record->price,
'price_unit'=>$record->price_unit
);
}
}
It is giving me this error:
Uncaught exception 'Services_Twilio_RestException' with message 'Could not decode response body as JSON. This likely indicates a 500 server error' in /Users/enmanuelcorvo/development/demos/twilio_usage/vendor/twilio/sdk/Services/Twilio.php:28
I tried wrapping the code inside a try catch like this
try {
// Loop over the list of records and echo a property for each one
foreach ($client->account->usage_records->last_month as $record) {
if ($record->count > 0) {
$call_record[] = array(
'category' => $record->category,
'count' => $record->count,
'usage' => $record->usage,
'price'=>$record->price,
'price_unit'=>$record->price_unit
);
}
}
} catch (Exception $e) {
echo($e->getMessage());
}
and I was able to get some usage data back but not all. I am missing things like calls-outbound which I know for sure we have some. So I think it breaks trying to fetch some categories and that is why it is trowing the error, but that is just a really wild guess. Any ideas what could be causing this?
Here is the stack-trace:
Stack trace:
**0 /Users/enmanuelcorvo/development/demos/twilio_usage/vendor/twilio/sdk/Services/Twilio.php(265): Base_Services_Twilio->_processResponse(Array)
1 /Users/enmanuelcorvo/development/demos/twilio_usage/vendor/twilio/sdk/Services/Twilio.php(236): Base_Services_Twilio->_makeIdempotentRequest(Array, '/2010-04-01/Acc...', 1)
2 /Users/enmanuelcorvo/development/demos/twilio_usage/vendor/twilio/sdk/Services/Twilio/ListResource.php(120): Base_Services_Twilio->retrieveData('/2010-04-01/Acc...', Array, true)
3 /Users/enmanuelcorvo/development/demos/twilio_usage/vendor/twilio/sdk/Services/Twilio/ListResource.php(179): Services_Twilio_ListResource->getPage(1, 50, Array, '/2010-04-01/Acc...')
4 [internal function]: Services_Twilio_ListResource->getPageGenerator(1, 50, in /Users/enmanuelcorvo/development/demos/twilio_usage/vendor/twilio/sdk/Services/Twilio.php on line 287**
Ross McKay has an article that suggest the issue is with the installation of PHP. As he puts it:
The error is caused by not having an up-to-date bundle of CA root certificates. This is typically a text file with a bunch of cryptographic signatures that curl uses to verify a host’s SSL certificate. You need to make sure that your installation of PHP has one of these files, and that it’s up to date.
Simply download the the latest CA root certificate bundle from here
And then within your php.ini file look for a section called [curl] (near the bottom in my case), and set your curl.cainfo according to where you place the cacert.pem, like so:
curl.cainfo=D:\Bitnami\wampstack\php\cacert.pem
Works like a charm!
Reference:
http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
In my case the error was caused by an incorrect entry of the accountSID and AuthToken. Make sure they're formatted as follows:
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
Replace with your accountSid and AuthToken found at www.twilio.com/Console

How to get authentication from user in linkedin?

I am new in creating a application in linkedin. Can some one help in getting the authorization??
I tried this code:
https://www.linkedin.com/uas/oauth2/authorization?response_type=code
&client_id=78lv1rv8ryh1hf
&scope=scope=r_fullprofile%20r_emailaddress%20r_network
&state=DCEEFWF45453sdffef424
&redirect_uri=http://www.mycoolsite.com
I am getting error saying that ...
error=unsupported_response_type&error_description=We+only+support+a+response_type+of+"code"%2C+but+you+passed+code+
There are a few things that can be improved:
you have not URL-encoded the redirect_uri parameter value
you're passing scope= in the scope value, which seems to be a typo/duplicate
you may have inserted a space/line-break in your URL since the following works for me:
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=78lv1rv8ryh1hf&scope=r_fullprofile%20r_emailaddress%20r_network&state=DCEEFWF45453sdffef424&redirect_uri=http%3A%2F%2Fwww.mycoolsite.com

Twitter REST Api 1.1 POST friendships/create

I was trying to implement Twitter friendships/create by using REST Api 1.1 with PHP. But no matter how I tried it returns with
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => Bad Authentication data
[code] => 215
)
)
)
and my code is (using Abraham library and changed twitterauth to v1.1)
$twitteroauth = new TwitterOAuth( $this->consumer_key, $this->consumer_secret, $oauth_token, $oauth_token_secret);
$test_create = $twitteroauth->post('friendships/create',array('follow'=>true,'user_id'=>'2529416xx'));
print_r($test_create);exit;
I'm not an expert (I've got the same problem), but I think you shouldn't change the oauth version since it remains 1.0a. More information can be found here https://dev.twitter.com/docs/api/1.1/overview#Authentication_required_on_all_endpoints and here https://dev.twitter.com/docs/auth/authorizing-request
The change it's only in the URL of the request, for instance:
https://api.twitter.com/1.1/statuses/mentions_timeline.json
I was having the same problem like yours also. And the solutions are simple : dont change the version number (remains 1.0) and change the host to $host = "https://api.twitter.com/1.1/";
that solved mine!
You can try this code
Here your_screen_name you need to pass your screen_name and instead of your_user_id you need to pass your user id
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['token'] , $_SESSION['token_secret']);
$connection->post('friendships/create', array('screen_name'=>'your_screen_name','user_id'=>'your_user_id','follow'=>'true'));

Google-api-client asking for access token

My requirement is to get top 20 links for a search query in google.com.
I am using the Google-api-client! for ruby.
Here goes the code I am using,
require 'google/api_client'
client = Google::APIClient.new
response = client.execute(
search.cse.list, 'key' => '<My Key>', 'cx' => '013036536707430787589%3A_pqjad5hr1a', 'alt' => 'json', 'q' => 'hello world'
)
Now I am facing three problems,
I want to use default Google search, so what should be the 'cx' value? One which I used, is from https://developers.google.com/custom-search/v1/using_rest#cx
I am getting no results, instead getting the following warning "ArgumentError: Missing access token." I solved this issue using a dummy token, by defining "client.authorization.access_token = '123'" . But I am not sure, if it is a correct solution or not.
After I define the access_token, still I am getting no result. Instead getting the warning "Invalid Credentials". But if I use the same URL(generated by the api), in the browser I am getting results.
Instead of setting a dummy access token, just set the authorization mechanism to nil:
client.authorization = nil
This way it won't send an authorization header and will just rely on the API key for identifying your app.

Resources