如何在未经授权的情况下访问youtube播放列表(oauth 2.0)?

时间:2015-02-11 18:15:36

标签: youtube-api google-oauth youtube-data-api

我尝试使用YouTube Data API v.3检索包含单个YouTube频道上所有上传视频信息的JSON对象。在我遇到的示例中,我看到他们首先使用某种授权创建了一个YouTube对象(如果我正确理解了Auth对象),可能是因为在这些示例中他们正在执行请求他们想要访问每个特定用户的YouTube频道的视频:

[...]

import com.google.api.services.samples.youtube.cmdline.Auth;

[...]

// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");

try {
    // Authorize the request.
    Credential credential = Auth.authorize(scopes, "playlistupdates");

    // This object is used to make YouTube Data API requests.
    youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
            .setApplicationName("youtube-cmdline-playlistupdates-sample")
            .build();

我无法确定是否有方法可以构建此YouTube对象以访问API中的其他方法,而无需在定期从一个特定频道请求视频信息而不需要每个频道的OA82授权时使用该应用程序的特定用户。

Builder方法采用什么参数,但我不知道要添加哪些参数(如果不是上面添加的参数)。如果没有OAuth授权(即需要用户登录),那么我是否有办法访问API?

1 个答案:

答案 0 :(得分:1)

您可以使用public class MyTests: IClassFixture<TestFixture> { TestFixture fixture; public MyTests(TestFixture fixture) { this.fixture = fixture; } [Fact] public void MyFirstTest() { ICustomerRepository customerRepository = new CustomerRepository(fixture.Configuration); CustomerService customerService = new CustomerService(customerRepository); } 通过请求channelId端点获取频道的视频,该端点不需要oauth:

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=ID&key=KEY

相关问题