Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting View Count in youtube api V3 in search video list #28

Open
irfanshehzad opened this issue May 15, 2015 · 2 comments
Open

Getting View Count in youtube api V3 in search video list #28

irfanshehzad opened this issue May 15, 2015 · 2 comments

Comments

@irfanshehzad
Copy link

I want to get videos view counts plus number of likes and dislikes
Here is my code in ruby

opts = Trollop::options do
opt :q, 'Search term', :type => String, :default => "#{search_params}"
opt :maxResults, 'Max results', :type => :int, :default => 25
end

client = Google::APIClient.new(:key => DEVELOPER_KEY,:authorization => nil)
youtube = client.discovered_api(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION)
opts[:part] = 'id,snippet,status,statistics'
opts[:pageToken] = session[:nextPageToken]

search_response = client.execute!(
  :api_method => youtube.search.list,
  :parameters => opts
)

It works fine if I set opts[:part] = 'id,snippet' but getting this error "Google::APIClient::ClientError (status)" on setting opts[:part] = 'id,snippet,status,statistics'

Please help me and tell me what should I do to get number of views , likes and dislikes in search list

Thanks in Advance

@khanetor
Copy link

khanetor commented Feb 3, 2016

You will need OAuth2 access. Developer_key alone does not have enough permission to get the statistics.

To make it easier to have OAuth2 auth, you should look into refreshToken.
Again, I don't have the Ruby code, but here is how to create an auth object in Java and I think you can adapt easily to your project.

new GoogleCredential.Builder()
    .setJsonFactory(JSON_FACTORY)
    .setTransport(HTTP_TRANSPORT)
    .setClientSecrets(clientId, clientSecret)
    .build()
    .setRefreshToken(refreshToken)

@augnustin
Copy link

Where is this documented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants