2015-01-13 79 views
2

這可能是因爲我正在閱讀完全錯誤的API文檔,但這裏我們繼續。Youtube API V3無法識別播放列表ID過濾器

我發送GET請求到https://www.googleapis.com/youtube/v3/playlistItems。在這一要求,我有授權頭,以及兩個參數:

"PART" : "contentDetails", 
"PLAYLISTID" : "UUy8_GJ_ZQ2SHm909UJ1AK-Q" 

我知道我的授權是正確的,因爲我使用的是相同的AUTH頭獲取和接收沒有問題的分析請求。

根據Google's docs,必須包含ID或播放列表ID。但是當我發送這個請求時,我得到了一個「沒有過濾器選擇」的錯誤400。

{ "error" : { "code" : 400, 
    "errors" : [ { "domain" : "youtube.parameter", 
     "location" : "", 
     "locationType" : "parameter", 
     "message" : "No filter selected.", 
     "reason" : "missingRequiredParameter" 
     } ], 
    "message" : "No filter selected." 
    } 
} 

如果我改變PlaylistID參數ID,請求成功完成,並返回一個空數組(空的,因爲該視頻ID顯然不存在。)

這是一個API錯誤嗎? API大小寫是否敏感? (從我所看到的,CFHTTP轉換爲大寫帕拉姆名稱,即使我用LCASE他們包裝)

更新:

代碼在這裏:https://gist.github.com/mborn319/13d7b9b03db10d97cd16

道歉,我不知道如何最好地分享200 CFML的行。

+2

你能發佈你的代碼嗎? – Leigh

+1

根據@Leigh:如果我們看不到它,很難對代碼中可能出現的問題發表評論;-) –

+0

我不知道足夠的CFML對此發表評論,但如果您對https執行簡單請求://www.googleapis.com/youtube/v3/playlistItems?part = contentDetails&playlistId = UUy8_GJ_ZQ2SHm909UJ1AK-Q&key = YOUR_KEY你會得到你的結果,所以我懷疑它是一個API錯誤。 – johnh10

回答

2

正如你指出的那樣,問題是大寫的PLAYLIST ID參數。

正如你所看到的,這個請求工作非常細: https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=UUy8_GJ_ZQ2SHm909UJ1AK-Q&access_token=[putValidAccessTokenHere]

{ 
    "kind": "youtube#playlistItemListResponse", 
    "etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/1T4SJss5RstUWWw6S4NPUKDWL-c\"", 
    "pageInfo": { 
     "totalResults": 1, 
     "resultsPerPage": 5 
    }, 
    "items": [ 
     { 
      "kind": "youtube#playlistItem", 
      "etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/s2P7FNuP_oK0sax4SB_fU9BVaLo\"", 
      "id": "UUeEJED-0K6VNZf3zbi8n5FA7Qu41XY55_", 
      "contentDetails": { 
       "videoId": "Y-Ft354b_vI" 
      } 
     } 
    ] 
} 

如果你與PLAYLISTID相同的查詢,你會得到你的錯誤輸出: https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&PLAYLISTID=UUy8_GJ_ZQ2SHm909UJ1AK-Q&access_token=[putValidAccessTokenHere]

{ 
    "error": { 
     "errors": [ 
      { 
       "domain": "youtube.parameter", 
       "reason": "missingRequiredParameter", 
       "message": "No filter selected.", 
       "locationType": "parameter", 
       "location": "" 
      } 
     ], 
     "code": 400, 
     "message": "No filter selected." 
    } 
} 

但我對不起,我不能告訴你如何在CF中發佈帶參數的參數(這是甚至可能嗎?),但這裏是對一些CF代碼的參考。他們使用舊的數據API,但他們通過獲取請求獲取數據。在這種情況下,params的處理方式可能會有所不同:http://davidosomething.com/blog/quick-access-to-the-youtube-api-with-coldfusion/

+0

我的歉意,我應該接受這個答案。我已經遇到其他API,比如Mailchimp,對某些參數區分大小寫,比如''Authorization:OAuth''''''授權:'Oauth''頭,這是非常令人沮喪的。 – coderMe

1

鑑於API區分大小寫,您必須確保ColdFusion保持大小寫,這可能會有點令人沮喪,因爲ColdFusion並不嚴格。

如果您使用點符號來指定結構中的鍵名稱,則CF幾乎總是將其大寫。

但是,如果使用括號表示指定鍵名稱,則會保留套管。

<cfset args.foo = "..."> key will be stored/transmitted as uppercase FOO 
vs. 
<cfset args["foo"] = "..."> key will be stored/transmitted as lowercase foo 


<cfset args["UPPERCASE"]="UPPERCASE"> 
<cfset args["lowercase"]="lowercase"> 
<cfset args["CamelCase"]="CamelCase"> 

所以,你應該能夠創建你的論點的結構,用括號

<cfset data["part"] = "contentDetails"> 
<cfset data["playlistId"] = "UUy8_GJ_ZQ2SHm909UJ1AK-Q"> 

然後遍歷您ARGS像以前

<cfhttp url="#arguments.url#" method="#arguments.type#" result="httpResult"> 
    <cfloop item="curArg" collection="#data#"> 
     <cfhttpparam name="#curArg#" value="#data[curArg]#" type="url" /> 
    </cfloop> 
</cfhttp> 

的API應該接受的在適當情況下的參數。

<cfdump var="#DeserializeJson(httpResult.filecontent.tostring())#"> 
+0

謝謝,我不知道這項技術會保持套路。非常有幫助! – coderMe

相關問題