GAN 게시자 ID 및 루비 (google-api-ruby-client)를 사용하여 Google 쇼핑 API에서 제품을 가져 오는 방법에 대한 예를 제공 할 수 있는지 궁금합니다. 내가 모으고 있는데 oauth를 사용하여 인증해야합니다. documentation은 매우 희소하여 모든 도움을 많이 주시면 감사하겠습니다.GAN 게시자 ID를 사용하여 Google 쇼핑 API에 액세스하는 Ruby 예제
4
A
답변
1
클라이언트와 쇼핑 API의 기본 사용법은 간단합니다.
require 'google/api_client'
client = Google::APIClient.new
client.authorization = nil
shopping = client.discovered_api("shopping", "v1")
result = client.execute(:api_method => shopping.products.list,
:parameters => { "source" => "public" })
GAN 게시자 ID로 쿼리하려면 알고 있어야합니다. OAuth 2를 사용할 수 있습니다. 루비 클라이언트에 대한 샘플을 http://code.google.com/p/google-api-ruby-client/wiki/OAuth2에서 볼 수 있습니다. 쇼핑에 사용하는 범위는 다음과 같습니다 버전 0.9.11로
http://code.google.com/apis/explorer/#_s=shopping&_v=v1&_m=products.list
0
이
require 'google/apis/content_v2'
def list_products
content_for_shopping = Google::Apis::ContentV2::ShoppingContentService.new
content_for_shopping.authorization = get_authorization(%w(https://www.googleapis.com/auth/content))
content_for_shopping.authorization.fetch_access_token!
content_for_shopping.list_products(ENV['GOOGLE_MERCHANT_CENTER_ID'])
end
def get_authorization(scopes)
cert_path = Gem.loaded_specs['google-api-client'].full_gem_path + '/lib/cacerts.pem'
ENV['SSL_CERT_FILE'] = cert_path
authorization = Google::Auth.get_application_default(scopes)
# Clone and set the subject
auth_client = authorization.dup
return auth_client
end
찾을도 쉽게 :
당신은 꽤 빨리이 밖으로 시도하는 API 탐색기를 사용할 수 있습니다 누구도 관심이 있다면 여기에 곱슬 곱슬을 사용하는 좋은 예 http://humbuckercode.co.uk/licks/code/google-search-api-for-shopping/ – seogrady
사용하지 마십시오. ClientLogin은 권장되지 않으며 어쨌든 공식 클라이언트를 사용해야합니다. –