Does Zend Gdata Support OAuth? - oauth

I installed Zend Gdata 1.11.2 but I don't see anything in it labeled OAuth... does it support OAuth?

I do it like this, for Docs, Calendar, and Picasa:
$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'signatureMethod' => 'HMAC-SHA1',
'consumerKey' => $CONSUMER_KEY,
'consumerSecret' => $CONSUMER_SECRET
);
$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$httpClient = $token->getHttpClient($oauthOptions,null);
$service = new Zend_Gdata_Photos($httpClient); //OR WHATEVER CLASS U WANT
...and then run your GData calls as normal through $service.

For OAuth there is seprate ZF component: Zend_OAuth.

No, it currently doesn't.
We integrate with a Google Documents for example, and all we can use currently is AuthSub. I haven't checked every line of code in there, but I think it's outdated in this respect. Of course we could create our own wrapper using OAuth, but this defeats the purpose of the framework for me.
Also, when you check out Google's examples, they tell you to use Zend_Oauth as well:
http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples (click on "PHP")

Oauth library is a part of the full ZF package.

Related

Can't get any account info, or review info

I've tried for hours now to figure this out but I'm completely stuck.
I have been approved for My Business APi and I created a service account and downloaded the json file for authentication.
I am using google-api-php-client and with google-api-my-business-php-client which provides the 'Google_Service_MyBusiness' class for use.
My code looks like this: -
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/google-api-my-business-php-client/MyBusiness.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__.'/myfile.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
if (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
return;
}
$client->setApplicationName("my_app");
$client->addScope('https://www.googleapis.com/auth/plus.business.manage');
$service = new Google_Service_MyBusiness($client);
$accounts = $service->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
But all that I ever get back is
Google_Service_Exception: That’s an error. The requested URL <code>/v3/accounts</code> was not found on this server. That’s all we know.
I notice that the documentation is now v4, i.e. v4/accounts, could this be the issue? Are these libraries out of date? How can I retrieve account and review data with v3?
Any help would be appreciated.
My end goal is the retrieve all the reviews for a location but right now just trying to get this to work as a prelude.
Answering my own question - I think the main issue is it turns out that My Business api doesn't support service accounts, you need to use oauth2.
Turns out that V3 is depreciated also so the libray I was using for MyBusiness API is useless, the other one works fine for updating access tokens.
For the reviews I am just using Curl and Simply building the URL with the ?access-token= value on the end of it.
For example to list all reviews
https://mybusiness.googleapis.com/v4/accounts/[acc-number]/locations/[location-id]/reviews?access_token=

tmhOauth twitter api stopped working with update_with_media call

So, this morning I got the following error:
{"errors": [{"message": "The Twitter REST API v1 will soon stop functioning.
Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",
"code": 68}]}
Since I was using the tmhOauth twitter api I went to look if there are updates for it, and as it seems there is an issue listed here.
I'm using the api to update the status with media like this:
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
array(
'media[]' => "#{$image}",
'status' => "{$text}"
),
true, // use auth
true // multipart
);
I found notes that I should just change the link to use 1.1 instead of 1 but it's still not working.
My main problem was that I didn't read the docs fully! While the change in the url from 1 to 1.1 was sufficient I missed the point by not looking that the new url for update_with_media,
as explained in the documentation, is https://api.twitter.com/1.1/statuses/update_with_media.json, namely it's api instead of the old upload subdomain.
So, now my api call looks like this and all works again:
$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => "#{$image}",
'status' => "{$text}"
),
true, // use auth
true // multipart
);
Hope this helps someone.
Instead of using tmhOauth api, use abraham's twitteroauth api ( updated to version 1.1 ) :
https://github.com/abraham/twitteroauth/tree/master/twitteroauth
and replace your code as follows :
$connection = new TwitterOAuth($twitter_consumer_key, $twitter_consumer_secret, $twAccessToken, $twAccessTokenSecret);
$parameters = array(
'media[]' => "#{$image}",
'status' => "{$text}"
);
$code = $connection->post('statuses/update_with_media', $parameters);

Can't get views by insightTrafficSourceType — YouTube Analytics API

So I'm using the 'google-api-client' gem with Rails, and I'm attempting to call the URL below in order to get video views by day and insightTrafficSourceType. This is a call that appears to be allowable from the Available Reports documentation page.
Additionally, I found that I was able to make this call by using the API Explorer tool provided by Google.
URL:
https://www.googleapis.com/youtube/analytics/v1beta1/reports?metrics=views&ids=channel==CHANNEL_ID&dimensions=day,insightTrafficSourceType&filter=video==VIDEO_ID&start-date=2013-01-15&end-date=2013-01-16&start-time=1970-01-01
Result:
{
:error=>
{
"errors"=>[
{
"domain"=>"global",
"reason"=>"invalid",
"message"=>"Unknown identifier (insightTrafficSourceType) given in field parameters.dimensions."
}
],
"code"=>400,
"message"=>"Unknown identifier (insightTrafficSourceType) given in field parameters.dimensions."
}
}
I'm not sure what extra data I can provide in the initial description of this bug, but as stated before I am making the call to the API with the Google::APIClient Ruby library. The actual code itself looks like this:
client.execute(
:api_method => api.reports.query,
:parameters => options
)
You are still referencing the old beta API, i.e., in your URL, you have 'v1beta' and you should have 'v1' there. Try replacing that and running it again. Also, you can look at the api explorer to see the exact URL that should be generated in live examples with your acct (once you enable OAuth) here:
https://developers.google.com/youtube/analytics/v1/
(Look at the bottom of the page.)
Finally, start-time isn't a parameter listed on the production version of the API, so you will want to remove that as well.

Can't get views by insightPlaybackLocationType — YouTube Analytics API

So I'm using the 'google-api-client' gem with Rails, and I'm attempting to call the URL below in order to get video views by insightPlaybackLocationType. This is a call that appears to be allowable from the Available Reports documentation page.
Unfortunately, I found that I was not able to make this call by using the API Explorer tool provided by Google.
URL:
https://www.googleapis.com/youtube/analytics/v1beta1/reports?metrics=views&ids=channel==CHANNEL_ID&dimensions=day,insightPlaybackLocationType&filter=video==VIDEO_ID&start-date=2013-01-15&end-date=2013-01-16&start-time=1970-01-01
Result:
{
:error=>
{
"errors"=>[
{
"domain"=>"global",
"reason"=>"invalid",
"message"=>"Unknown identifier (insightPlaybackLocationType) given in field parameters.dimensions."
}
],
"code"=>400,
"message"=>"Unknown identifier (averageViewDuration) given in field parameters.dimensions."
}
}
I'm not sure what extra data I can provide in the initial description of this bug, but as stated before I am making the call to the API with the Google::APIClient Ruby library. The actual code itself looks like this:
client.execute(
:api_method => api.reports.query,
:parameters => options
)
You'll need to set the version to v1 not v1beta1.
The start-time parameter seems wrong to me. You already specified start-date
Check the API explorer:
http://developers.google.com/apis-explorer/#p/youtubeAnalytics/v1/youtubeAnalytics.reports.query?ids=channel%253D%253DCHANNEL_ID&start-date=2012-12-15&end-date=2013-01-16&metrics=views&dimensions=day%252CinsightPlaybackLocationType&filters=video%253D%253DVIDEO_ID&_h=4&

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'));

Resources