dongtang6718 2016-06-01 23:03
浏览 20
已采纳

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.

  • 写回答

1条回答 默认 最新

  • dongqu1783 2016-06-02 09:32
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥15 怎么实现输入一个要删除的数后删除后显示剩余数再输入再删除显示剩余数(语言-c语言)
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection