2010-08-07 106 views

回答

1

我已經回答了這是其他一些帖子,我發現它們與此類似......所以對於使用google-api-client(適用於任何google apis)的ruby,有幾個與認證使用api密鑰,而不是OAuth身份驗證和輸入...

我已經列出了這個過程(使用api密鑰服務器端)在the code abode

在構建客戶端時,您必須明確設置authorzation參數爲nil,否則gem會嘗試使用OAuth進行身份驗證,所以如果僅使用api鍵從服務器調用,您將始終獲得401 Unauthorized。 the code abode - google-api-client for ruby

require 'openssl' 
    OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE 

    require 'google/api_client' 
    client = Google::APIClient.new(:key => 'your-api-key', :authorization => nil) 
    search = client.discovered_api('customsearch') 

    response = client.execute(
    :api_method => search.cse.list, 
    :parameters => { 
     'q' => 'the hoff', 
     'key' => 'your-api-key', 
     'cx' => 'your-custom-search-id' 
    } 
) 
相關問題