用.Net调用GoogleAPI获取Google Task列表失败_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 用.Net调用GoogleAPI获取Google Task列表失败

用.Net调用GoogleAPI获取Google Task列表失败

 2011/10/31 8:29:48  tedeum  http://tedeum.iteye.com  我要评论(0)
  • 摘要:代码如下staticvoidMain(string[]args){//Registertheauthenticator.TheClientIDandsecrethavetobecopiedfromtheAPIAccess//tabontheGoogleAPIsConsole.varprovider=newNativeApplicationClient(GoogleAuthenticationServer.Description);provider
  • 标签:.net API Google net 失败 googleapi

代码如下

        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());时浏览器里面的结果是:

OAuth2.0 错误:invalid_scope

You can email the developer of this application at:jipen...@gmail.com

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

了解详情

OAuth2 请求详情
  • from_login=1
  • response_type=code
  • redirect_uri=urn:ietf:wg:oauth:2.0:oob
  • as=4428b3c3ae4887d4
  • pli=1
  • hl=zh-CN
  • client_id=272908629865.apps.googleusercontent.com
  • scope=Tasks
发表评论
用户名: 匿名