首頁  >  文章  >  後端開發  >  用.Net呼叫GoogleAPI取得Google Task列表失敗

用.Net呼叫GoogleAPI取得Google Task列表失敗

巴扎黑
巴扎黑原創
2016-12-20 09:22:061870瀏覽

程式碼如下

static void Main(string[] args)
        {
            // Register the authenticator. The Client ID and secret have to be copied from the API Access
            // tab on the Google APIs Console.
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            provider.ClientIdentifier = "272908629865.apps.googleusercontent.com";
            provider.ClientSecret = "4UmdiNDILOV5bv-qRQz2XUwA";
            var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);
            // Create the service and register the previously created OAuth2 Authenticator.
            var service = new TasksService(auth);
            TaskLists results = service.Tasklists.List().Fetch();
            foreach (TaskList list in results.Items)
            {
                Console.WriteLine(list.Title);
            }
        }
        private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
        {
            // Get the auth URL:
            IAuthorizationState state = new AuthorizationState(new[] { TasksService.Scopes.Tasks.ToString() });
            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
            Uri authUri = arg.RequestUserAuthorization(state);
            // Request authorization from the user (by opening a browser window):
            Process.Start(authUri.ToString());
            Console.Write("  Authorization Code: ");
            string authCode = Console.ReadLine();
            Console.WriteLine();
            // Retrieve the access token by using the authorization code:
            return arg.ProcessUserAuthorization(authCode, state);
        }

運行

Process.Start(authUri.ToString());時瀏覽器裡面的結果是:

OA 2.0 錯誤:this.0 錯誤:this 相同 scocan 錯誤:this 2.0 錯誤:this.0 錯誤) application at:jipen...@gmail.com

Some requested scopes were invalid. {invalid=[Tasks]}

   

   


🎜🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn