I am trying to access earnings and monetizedPlaybacks from the YouTube analytics API and all I am able to get is "401 Unauthorized"-Responses. I have logged in using OAuth2 and I used the scopes
https://www.googleapis.com/auth/yt-analytics-monetary.readonly
https://www.googleapis.com/auth/yt-analytics.readonly
https://www.googleapis.com/auth/youtube.readonly
Here is the Java-Snippet that I use in my application:
analytics.reports()
.query("channel==" + channelId, "2013-06-01", "2013-07-01", "earnings,views,monetizedPlaybacks")
.setFilters("video==" + videoId)
.setDimensions("month")
.execute()
I also tried to use the APIs Explorer, but this behaves identical.
If I retrieve only the number of views (no earnings and not monetizedPlaybacks) everything works fine.
I found this bugreport that claims that the API is broken, but it causes remarkably few reactions.
Any ideas appreciated.
This feature is currently not available in the API for youtube partner even though the information can be retrieved using the GUI. Instead a CMS-Account is needed.
There is a bugreport / feature request about the issue:
https://code.google.com/p/gdata-issues/issues/detail?id=4826
Related
I am trying to use Google OAuth2.0 for authentication. Everything is working fine but on initial(first) loading it is taking extra time (30 seconds-RequestTimeOut) on client side(Web-App) to load prompt. I've checked the Network Tab (Developer Console-Chrome), where I've found that it is trying to make call to
https://accounts.youtube.com/accounts/CheckConnection?pmpo=VALUE&v=VALUE×tamp=VALUE.
This request is failing with ERR_TIMED_OUT, and In my organization we don't have access to Youtube (That I'm aware of it). But Why and Where my application is making request to Youtube API is my question. If so How do I stop this (fetch accounts from youtube)?
The scope of My App goes like this
"scope": "https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
It is happening on initial load itself, later it is giving 200 status for the same request. What am I missing.
I'm completely new to this. (Sorry, If it is noob question)
Thanks in advance.
Edit::
I came to know why it is making request to youtube api, It is trying to fetch any other accounts(login users) from youtube(gmail-accounts). But how to stop making request to youtube(accounts.youtube.com). It is fine for my application to fetch accounts from google(accounts.google.com).
Thanks.
Google puts an iframe inside google o-auth account picker.
Google oauth and youtube accounts iframe
Analyzing the javascript inside that iframe, we find some evidence that, this might be an approach to load youtube session, in order to get the userId for the current logged user in Youtube.
By creating an iframe, you get the normal context of opening an website, this is, you get access to session information.
And it's exactly what this is used for, proof:
//# sourceURL=/_/mss/boq-identity/_/js/k=boq-identity.AccountsDomaincookiesCheckconnectionJs.pt_PT.4FJ4-a_ocZ8.es5.O/d=1/ct=zgms/rs=AOaEmlHUdMtrscDWG6wHCiHHFunuI9afAg/m=base
if (window.parent && window.parent.postMessage) {window.parent.postMessage( google.checkconnection.getMsgToSend('youtube', 'some_id'), 'https:\/\/accounts.google.com');}</script>
iframes can communicate, as long as one another is listening to this messages.
At least a year ago, if I go to
http://gdata.youtube.com/feeds/api/videos?v=2&max-results=1&q=intitle:"Relapse"+intitle:"Eminem"&orderby=viewCount
from FireFox browser, I could the list of video titles that meet the search query in this address.
But now it doesn't work.
Has it been deprecated?
#user3123767 The YouTube Data API (v2) has been officially deprecated as of March 4, 2014. Please refer to our deprecation policy for more information. Please use the YouTube Data API (v3) for new integrations and migrate applications still using the v2 API to the v3 API as well. Ref
All calls to Google APIs now require that you send Your Api Key, which you can obtain one from Here
Once you got your API Key You can Make various calls
For example Search for videos using the key word "Hollywood"
Run this code and see the result in console
(function($){
function SearchYouTube(queryToSearch,pageToken,ApiKey,maxResults){
var
YoutubeUrl="https://www.googleapis.com/youtube/v3/",
pageToken=pageToken,
maxResults=maxResults,
ApiKey=ApiKey,
$.get(YoutubeUrl+"search?q="+queryToSearch,{
part : 'snippet',
pageToken:pageToken,
key:ApiKey,
maxResults:maxResults
},
function(data) {
//let check if request is granted with our Api Key
if(!data.items[0]){console.log("System Configuration Error");}
//If request granted okay
var
videoId=data.items[0].id.videoId,
videoImgUrl=data.items[0].snippet.thumbnails.high.url,//medium | default | high
videoTile=data.items[0].snippet.title,
nextPageToken=data.items[0].nextPageToken;// Useful if you want the next set of datas
//Display data on page here if you want
//See console Log of results that you can use
console.log(data);//Dump data
}//Success
);
}
//Usage
SearchYouTube("Hollywood","","xxx Your Api Key xxx",5);
//==================All Closed==========
})(jQuery);
See Working Sample Here
could be a few reasons.
YouTube API v2.0 is deprecated not sure if it totally down now or not.
All calls to Google APIs now I think require that you send a at the very least a public API key. I just tested the following
http://gdata.youtube.com/feeds/api/videos?q=skateboarding+dog&start-index=21&max-results=10&v=2&key=[api
key]
It returned
This webpage is not available
I think I am going to have to say that its not working anymore you should try and use YouTube API v3 instead.
Requirement: I am trying to upload videos to my Youtube channel through Youtube Data API for Java. The request is sent from a war file hosted on tomcat container.My application is not for external users and I only use it to upload my own generated videos. With the help of the api documentation and sample youtube code snippets, I have successfully managed to post video on youtube.
Problem: The issue is that whenever I try to run the code, I get prompted for
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload
Since I run this code on a remote server, it is not possible for me to always open this URL on the browser. Since I have registered my web app in Google Console, and got a pair of Client ID and Secret and a JSON file, so Youtube must allow me to publish videos by default to atleast my channel, isin't it?
I have used the Auth.java file(provided in youtube java code samples) and the following code is where this thing happens.
// Authorize.
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user#.com");
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
Please help here as this is really eating up a lot of my development time.
You should only need to authenticate your code once. When your code is authenticated you get a refresh token back. the refresh token will then allow you to get a new access token the next time your code runs.
There is no service account authentication for the YouTube api. Your code has to be authenticated by you the first time in order to get that refresh token.
I am not a java programmer but from a quick check of the documentation it looks quite similar to what I do in.net. You need to create a datastore to to store the first refreshh token then you should be able to run your code in the future with out needing to authenticate it again.
** UPDATE **
It truly seems that Google has just screwed every single person on the planet by absolutely requiring user interaction to upload a video. Of course I know, they are free. Exactly what I warned the client years ago about, so I don't need to be reminded. Thank You.
So I would like to try to take this in a different direction and just find a loophole and a workaround to still keep doing what we are doing in spite of Google's complete lack of support or caring in any way about the developers and what they have to deal with.
It would be different if you can actually call a phone number and talk to a human being about YouTube Partner access, but you can more quickly get access to the Illuminati.
OAuth 2.0 is now the only supported authentication method period. It does require user interaction.
But what about that token? Does anybody know how long the token lasts?
If I can obtain a token just once using user interaction and place it in the database, I can automate possibly hundreds or thousands of interactions afterwards.
In other words, I'm trying to turn the user interaction into a speed bump instead of a concrete wall.
If anybody has any examples of obtaining that token, caching it, and using it afterwards, that would be a godsend to me right now.
Thanks for the comments and the help. I'm not surprised that the YouTube Developers Forum just folded and said to come here instead :)
It seems that Google has completely pulled the plug on the existing dashboard.
https://code.google.com/apis/youtube/dashboard/gwt/index.html
That link is now 404'd. Tried from several different browsers on different systems.
Registered under the new Google APIs Console already, but still get the problem.
// Set the authentication URL for this connection object
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
// Try to connect to YouTube with the channel credentials passed
try {
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = $channelfields['EMAIL_ADDRESS'],
$password = $channelfields['PASSCODE'],
$service = 'youtube',
$client = null,
$source = 'Redacted Data',
$loginToken = $channelfields['CACHED_TOKEN'],
$loginCaptcha = '',
$authenticationURL);
} catch (Zend_Gdata_App_HttpException $httpException) {
$update_error['response_body'] = $httpException->getRawResponseBody();
$update_error['error'] = 1;
} catch (Zend_Gdata_App_Exception $e) {
$update_error['message'] = $e->getMessage();
$update_error['error'] = 1;
}
This code has worked perfectly fine before, but does not work with the older API key, or the newer one generated inside the Google APIs console.
I'm attempting a simple upload and this concerns me greatly:
"The service account flow supports server-to-server interactions that do not access user information. However, the YouTube Data API does not support this flow. Since there is no way to link a Service Account to a YouTube account, attempts to authorize requests with this flow will generate a NoLinkedYouTubeAccount error."
From all reports it seems that Google has forced YouTube uploads to become interactive in all cases precluding all possibility of platforms that automatically upload generated content from working at all.
Any help or insights into the process is appreciated.
P.S - Ohhh, it's been awhile since I looked at that system and Google shut down the YouTube Developer Forums and said "YOU" were responsible for their support now :)
OAuth2 does support the ability to avoid user interaction through the offline access type parameter (ie, using access_type=offline). Check out Google documentation for details.
The solution is really rather simple. Your app needs to use oauth to request offline access. It will be given an access cide which you convert to a refresh token, which is the thing you store in your database. This doesn't expire. Well actually it sometimes does, but that's another story. Whenever you need to access the api, use the stored refresh token to request an access token which you include in each api call.
See https://developers.google.com/accounts/docs/OAuth2WebServer for details.
I don't know what you did but https://code.google.com/apis/youtube/dashboard/gwt/index.html works perfectly fine for me. Maybe it was a temporary issue. If you want no user interaction you HAVE to use YouTube API v2 OR you have to use v3 with methods that don't require authentification OR you have to provide your own youtube account credentials which is not recommended and probably not appropriate for you situation.
Several issues to respond here, I think.
1) The older API console has not been removed, but I've noticed intermittent outages to it and to the newer API console while Google is rolling out their new "cloud console."
2) ClientLogin was officially deprecated in April of 2012, not just 48 hours ago. Jeff Posnick has detailed all the changes over the months (and related ones, such as AuthSub, Youtube Direct, etc.) at his blog (apiblog.youtube.com).
3) You're right that, with v3 of the APIs, you cannot do automatic uploads across the board, as the oAuth2 flow requires user interaction. However, given the limited description of your use case, using refresh tokens is probably your best bet. If the content is user generated, somewhere they must be logging into your app, correct? (so that your app knows which credentials to leverage to do the uploads). At the point they're logging into your app, and you're starting the oAuth2 flow, you just have to hit the first oAuth endpoint and pass it the parameter access_type=offline (along with any other parameters). This will ensure that, when they grant that initial permission, you're returned a refresh token instead of an access token. With that refresh token, you can exchange it for multiple access tokens as needed (an access token lives for about an hour. I don't know how long a refresh token lives, but I've never had one expire before my own login cookies did, and then I just get a new one when my users re-login to my app).
Here's some more info on how to use the refresh token; note, too, that the various google api client libraries make it pretty smooth.
https://developers.google.com/accounts/docs/OAuth2WebServer#refresh
Also, this video tutorial from a Google Developers Live broadcast a couple of months ago might help illustrate the point: http://www.youtube.com/watch?v=hfWe1gPCnzc -- it's using the oAuth playground rather than a client library, but the concept is the same.
The answer is to use google-api-php-client, create an interactive auth page, and set up YouTube API v3 correctly with the new API console.
You can create a very simple page that will authenticate for the supplied channel and then store the correct token in your database. Is already working and uploading hundreds of videos on one channel. You do need to remember to fully activate yourself under the new API console and add the services required. Just keep authenticating and adding the services it says it needs. After that, the regular v3 upload process works just fine. On failure send a group an email and they can get a new token in 10 seconds.
Not the most elegant solution, but the documentation from Google is far from elegant anyways that Stack Overflow is now their front line support.
Just hang in there, a solution is always found. Don't give up!
I didn't get here by myself either, the other answers on this page helped me get all the way to this point. Thanks guys.
P.S - Don't forget the scopes
$client->setScopes("https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload");
I am trying to use the Youtube data API from an app, and I'd like to just request permission to upload videos, not to manage their entire Youtube account.
When I try to request an access token for the scope https://www.googleapis.com/auth/youtube.upload, I get back an error saying it is an invalid scope. I've given the app permission to the Youtube v3 data API.
According to the v3 youtube docs, these are the supported scopes:
https://www.googleapis.com/auth/youtube - Manage your YouTube account.
https://www.googleapis.com/auth/youtube.readonly - View your YouTube account.
https://www.googleapis.com/auth/youtube.upload - Upload YouTube videos and manage your YouTube videos.
The only one of these 3 that works for me is "https://www.googleapis.com/auth/youtube".
This is the request I am attempting:
curl -d "client_id=id&scope=https://www.googleapis.com/auth/youtube.upload" https://accounts.google.com/o/oauth2/device/code
And this is the response:
{
"error" : "invalid_scope",
"error_description" : "Not authorized to request the scopes: [https://www.googleapis.com/auth/youtube.upload]",
"error_uri" : "http://code.google.com/apis/accounts/docs/OAuth2.html"
}
I am thinking that maybe this type of request just doesn't work for device codes? The youtube.upload scope request seems to work fine in the oauth2 playground.
Update: This issue has been fixed.
This scope by itself was not whitelisted for the devices. Filed a request internally.
On the other hand, as explained here, Stackoverflow is for programming questions, you can use public issue tracker for bug reports or feature requests.
Feel free to file a bug report in issue tracker to get updated on this issue.