Youtube Content ID API总是返回Not Found

Youtube Content ID API总是返回Not Found

问题描述:

My account is connected to a CMS but I can't see Youtube Content ID in API Library. However, I see it in my Enabled APIs!! (It appeared after I try "Authorize requests using OAuth 2.0" in Youtube Content ID API reference doc). I can test the API in reference doc and it shows data from my CMS. But when I call the API from my program, the response is always like this:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

This is my implementation using Go:

func TestYoutubeAPI(w http.ResponseWriter, r *http.Request)  {
    data, err := ioutil.ReadFile("./google-service-key.json")
    if err != nil {
        log.Fatal(err)
    }
    config, err := google.JWTConfigFromJSON(data, "https://www.googleapis.com/auth/youtubepartner", "https://www.googleapis.com/auth/youtube.force-ssl", "https://www.googleapis.com/auth/youtube")
    if err != nil {
        log.Fatal(err)
    }
    client := config.Client(oauth2.NoContext)

    request, _ := http.NewRequest("GET", "https://www.googleapis.com/youtube/partner/v1/assetSearch", nil)
    request.Header.Add("Accept", "application/json")

    query := request.URL.Query()
    query.Add("createdAfter","2015-01-29T23:00:00Z")
    query.Add("key", "XXX")
    request.URL.RawQuery = query.Encode()

    response, err := client.Do(request)

    if err != nil {
        fmt.Fprintln(w, err)
    } else {
        responseBody, _ := ioutil.ReadAll(response.Body)
        fmt.Println(response.Status)
        fmt.Fprintln(w, string(responseBody))
    }
}

Other APIs (Youtube Data API) work fine with this code. However, I can't get my expected result with Youtube Content ID API.

Anyone got experience in this please help me. Thank you.

我的帐户已连接到CMS,但在API库中看不到Youtube Content ID。 但是,我在启用的API中看到了它! (它在我尝试使用Youtube Content ID API参考文档中的“使用OAuth 2.0授权请求”后出现)。 我可以在参考文档中测试API,它会显示来自CMS的数据。 但是,当我从程序中调用API时,响应始终是这样的: p>

  {
“错误”:{\  n“错误”:[
 {
“域”:“全局”,
“原因”:“未找到”,
“消息”:“未找到” 
} 
],
“代码 “:404,
”消息“:”未找到“ 
} 
} 
  code>  pre> 
 
 

这是我使用Go的实现: p>

  func TestYoutubeAPI(w http.ResponseWriter,r * http.Request){
 data,err:= ioutil.ReadFile(“ ./ google-service  -key.json“)
 if err!= nil {
 log.Fatal(err)
} 
 config,err:= google.JWTConfigFromJSON(data,” https://www.googleapis.com/auth  /youtubepartner”、“https://www.googleapis.com/auth/youtube.force-ssl”、“https://www.googleapis.com/auth/youtube”)
如果错误!= nil {
  log.Fatal(err)
} 
客户端:= config.Client(oauth2.NoContext)
 
请求,_:= http.NewRequest(“ GET”,“ https://www.googleapis.com/  youtube / partner / v1 / assetSearch”,ni  l)
 request.Header.Add(“ Accept”,“ application / json”)
 
查询:= request.URL.Query()
 query.Add(“ createdAfter”,“ 2015-01-29T23  :00:00Z“)
 query.Add(” key“,” XXX“)
 request.URL.RawQuery = query.Encode()
 
响应,错误:= client.Do(request)
  
 if err!= nil {
 fmt.Fprintln(w,err)
} else {
 responseBody,_:= ioutil.ReadAll(response.Body)
 fmt.Println(response.Status)
  fmt.Fprintln(w,string(responseBody))
} 
} 
  code>  pre> 
 
 

其他API(Youtube Data API)可以在此代码下正常工作。 但是,使用Youtube Content ID API无法获得预期的结果。 p>

任何有此经验的人请帮助我。 谢谢。 p> div>

I found the answer!

Because I used Google Service Account to interact with Google API. It seems to create a new user account. So that I have to grant permission on Youtube CMS by adding Service account client email to Youtube CMS. Finally, I can access Youtube CMS using the API.