我有一个为客户创建和上传视频的应用程序。在尝试上传之前,客户授予授权,并保存由此产生的访问和刷新令牌。有时会发生这样的情况:客户的谷歌账户没有关联的YouTube频道。我检测到了这一点,并为他们创建了一个通道。这通常很好用。但并非总是如此。以下是创建通道失败的示例:
Obtaining access token for Customer
post https://accounts.google.com/o/oauth2/token
HTTP Response: 200
{
"access_token" : "_new_access_token_",
"token_type" : "Bearer",
"expires_in" : 3600
}
Uploading video '_video_name_' for Customer
post http://uploads.gdata.youtube.com/feeds/api/users/default/uploads
Authorization: Bearer _new_access_token_
GData-Version: 2.1
X-GData-Key: key=_GData_Key_
Slug: n3n1xs.mp4
Content-Type: multipart/related; boundary="51d366cb05b71"
Content-Length: 255958407
Connection: close
HTTP Response: 403
<?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:service</domain><code>youtube_signup_required</code></error></errors>
Obtaining channel names for Customer
get https://gdata.youtube.com/feeds/api/suggest/username?hint=CustomerNameVT&fields=entry%2Ftitle
GData-Version: 2.1
X-GData-Key: key=_GData_Key_
HTTP Response: 200
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom'><entry><title>CustomerNameVT</title></entry><entry><title>VTCustomerName</title></entry><entry><title>VTNameCustomer</title></entry><entry><title>CustomerVTName</title></entry><entry><title>CustomerNameVT1</title></entry><entry><title>NameCustomerVT</title></entry><entry><title>NameVTCustomer</title></entry></feed>
Linking YT channel for Customer (CustomerNameVT)
put https://gdata.youtube.com/feeds/api/users/default
Authorization: Bearer _new_access_token_
Content-Type: application/atom+xml
GData-Version: 2.1
X-GData-Key: key=_GData_Key_
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:yt='http://gdata.youtube.com/schemas/2007'><yt:username>CustomerNameVT</yt:username></entry>
HTTP Response: 403
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>ServiceForbiddenException</code><internalReason>Forbidden</internalReason></error></errors>
请注意,请求的名称是suggestingusernameapi建议的第一个名称。据我所见,这应该行得通。通常是这样。这次怎么了?
用于将Google帐户链接到新频道的API已被弃用。
我们目前的建议是,从https://youtube.com/create_channel(或相当于m.youtube.com的网站)。