kylejginavan / youtube_it

An object-oriented Ruby wrapper for the YouTube GData API
http://groups.google.com/group/ruby-youtube-library
595 stars 223 forks source link

insight_uri for Video returning nil? #79

Closed aharpole closed 12 years ago

aharpole commented 12 years ago

I've been using YouTubeIt to download the Insight data CSV files for Channels, and I'd like to also start doing it for individual videos as well. I discovered that the inisght_uri property of the videos ends up being null.

Upon investigating this, it appears that the feed I get from YouTube for the video is missing this insight URI link element. After discussing this with YouTube API support, they are convinced that I didn't properly authenticate with YouTube to get the data. I used HTTPScoop to see what was happening under the hood. The GET that is being requested is:

http://gdata.youtube.com/feeds/api/videos/165_M-qhL9A?v=2&key=[redacted]

But what I get back from that doesn't include the Insight URI. The fact that it's going over HTTP and not HTTPS might also lead me to believe something isn't authenticated.

I'm using OAuth and I have authenticated my client with this OAuth key, but getting the video using video_by doesn't get me a video object which contains the insight URI.

Is there another way I can instantiate the video object so that it downloads the video's feed using the OAuth so that it includes the insight URI?

yaauie commented 12 years ago

Unfortunately YouTubeIt makes a lot of its calls without passing through authentication, and there are a lot of code-paths that are hard to follow & end up putting you in this state.

This line right here is likely to blame. Unfortunately I don't have the resources to untangle it, but maybe someone else will? As a workaround you can likely use YouTubeIt::Client#my_video or YouTubeIt::Client#my_videos which does pass through the authenticated session.

aharpole commented 12 years ago

Thanks, @yaauie. I'll take a look at those workarounds, and if I'm feeling brave I'll trudge through YouTube's API documentation and submit a pull request when I get the chance.

chebyte commented 12 years ago

ey @aharpole if you use @client.my_videos this get ok the insight_url this is good for you?

puts @client.my_videos.videos.first.insight_uri
http://insight.youtube.com/video-analytics/csvreports?query=iLgmkRKVu34&type=v&starttime=1235865600000&endtime=1336521600000&user_starttime=1335916800000&user_endtime=1336521600000&region=world&token=krS4wgOCu7MwbiU1VP84_v3SOZl8MTMzNjY3ODM1M0AxMzM2Njc2NTUz&hl=en_US
chebyte commented 12 years ago

you can use too

@client.my_video(id)

with these methods you can use insight_url

chebyte commented 12 years ago

so methods like

video_by and videos_by 

doesnt use authentication cause the idea is that you can search videos without authtentication,

by the way the param

insight_url 

just is available for your own videos, so if you need get this you can use methods like

client.my_videos or client.my_video(video_id)

these methods are using authentication

cheers!

aharpole commented 12 years ago

Ah, okay. That makes sense. Thanks so much! On May 10, 2012, at 12:21 PM, chebyte wrote:

so methods like

video_by and videos_by

doesnt use authentication cause the idea is that you can search videos without authtentication,

by the way the param

insight_url

just is available for your own videos, so if you need get this you can use methods like

client.my_videos or client.my_video(video_id)

these methods are using authentication

cheers!


Reply to this email directly or view it on GitHub: https://github.com/kylejginavan/youtube_it/issues/79#issuecomment-5634186

yaauie commented 12 years ago

@chebyte FYI: YouTube rate limits are apparently tied to a combination of the user you're authenticated as and your IP address; unauthenticated requests for a given IP hit rate limits significantly faster than authenticated ones, and it's encouraged to make all requests as your authenticated user. There really is no reason to make unauthenticated requests if the authentication is available.

Authentication (are you who you say you are?) & Authorization (can who you say you are perform a given action?) are two very different things; to only use authentication when you need it for authorization means a whole mess of code paths that are not covered by uniform error handling, that requests are being made outside the client (e.g., in YouTubeIt::Parser::FeedParser#initialize), and generally makes the code significantly harder to maintain & debug.