YouTube数据Api v3身份验证

时间:2015-08-12 12:57:07

标签: c# youtube-api windows-8.1

请帮帮我!我需要使用YouTube Data Api v3来管理youtube帐户。 我按照网站api上的说明,但他们的示例不是为Windows 8.1应用程序设计的。我发现这个示例应用程序拆解了tubecast,但它对我不起作用。 我试图获取日志服务的记录:

GoogleAuthorizationCodeFlow.Initializer init = new GoogleAuthorizationCodeFlow.Initializer();
        ClientSecrets clientSecrets = new ClientSecrets()
        {
            ClientId = ClientID,
            ClientSecret = ClientSecret
        };
        init.ClientSecrets = clientSecrets;
        init.Scopes = new string[] { YouTubeService.Scope.Youtube };
        myAuthorizationCodeFlow = new GoogleAuthorizationCodeFlow(init);
        UserCredential credential = null;
        CancellationToken cancellationToken = new CancellationToken();
        TokenResponse tokenResponse = myAuthorizationCodeFlow.LoadTokenAsync(ClientID, cancellationToken).FinalResult<TokenResponse>();
        if(tokenResponse!=null)
        {
            credential = new UserCredential(myAuthorizationCodeFlow, ClientID, tokenResponse);
        }

        BaseClientService.Initializer initializer1 = new BaseClientService.Initializer()
        {
            ApiKey = myApiKey,
            ApplicationName = myAppName,
            HttpClientInitializer = credential
        };
        this.myYoutubeServiceLogged = new YouTubeService(initializer1);


 public static T FinalResult<T>(this Task<T> pTask)
    {
        T result;
        try
        {
            pTask.Wait();
            result = pTask.Result;
        }
        catch (Exception)
        {
            result = pTask.Result;
        }
        return result;
    }

但是tokenResponse为空,我做错了什么?

0 个答案:

没有答案