Youtube iOS创建播放列表未经授权

时间:2018-02-13 15:08:55

标签: ios swift youtube youtube-api youtube-data-api

我遵循了这个堆栈溢出问题:create playlist in Youtube api

但是,当我提出请求时,它会在未经授权的情况下提供错误。 我将范围设置为kGTLRAuthScopeYouTubeYoutubepartner,并尝试了kGTLRAuthScopeYouTube。我也在swift中实现了这个项目,但我觉得我的实现是正确的。我没有客户的秘密:

let clientID = "my_client_id"
        if let loginvc = GTMOAuth2ViewControllerTouch(scope: kGTLRAuthScopeYouTube, clientID: clientID, clientSecret: "", keychainItemName: nil, completionHandler: { (vc, auth, error) in
            vc?.dismiss(animated: true, completion: nil)
            if error == nil {
                self.youtubeService.authorizer = auth
                self.createYoutubePlaylistWithTitle("Name", { (id) in
                    print(id)
                })
            } else {
                print(error!.localizedDescription)
            }
        }) {
            self.present(loginvc, animated: true, completion: nil)
        }

这是createYoutubePlaylistWithTitle函数:

func createYoutubePlaylistWithTitle(_ title : String,_ completion : @escaping (String) -> Void ) {
    let playlist = GTLRYouTube_Playlist()

    let playlistSnippet = GTLRYouTube_PlaylistSnippet()
    playlistSnippet.title = title

    let playlistStatus = GTLRYouTube_PlaylistStatus()
    playlistStatus.privacyStatus = "private"

    playlist.snippet = playlistSnippet
    playlist.status = playlistStatus

    let query = GTLRYouTubeQuery_PlaylistsInsert.query(withObject: playlist, part: "snippet,status")
    youtubeService.executeQuery(query) { (ticket, id, error) in
        if error == nil {
            //success
            if let playlistOut = id as? GTLRYouTube_Playlist {
                let playlistid = playlistOut.identifier!
                completion(playlistid)
            }
        } else {
            print(error!.localizedDescription)
        }
    }

}

1 个答案:

答案 0 :(得分:0)

在这种情况下的问题是我的谷歌帐户没有设置youtube - 我没有频道,因此我无法制作播放列表...真烦人和愚蠢的错误让我绞尽脑汁几个小时。