Api 代码C#使用Google OAuth对Google帐户进行签名

Api 代码C#使用Google OAuth对Google帐户进行签名,api,google-oauth,Api,Google Oauth,我的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Google.Apis.Blogger.v3; using Google.Apis.Blogger.v3.Data; using Google.Apis.Services; using System.Diagnostics; using Goo

我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Apis.Blogger.v3;
using Google.Apis.Blogger.v3.Data;
using Google.Apis.Services;
using System.Diagnostics;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Util;

namespace BloggerTest
{
 class Program
 {
  static void Main(string[] args)
  {
   string apiKey= "{API-KEY}";
   string blogUrl= "{BLOG-URL}";

   string clientID = "{CLIENT_ID}";
   string clientSec = "{CLIENT_SECRET}";

   NativeApplicationClient provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
   {
    ClientIdentifier = clientID,
    ClientSecret = clientSec
   };

   OAuth2Authenticator<NativeApplicationClient> auth = new OAuth2Authenticator<NativeApplicationClient>(provider, getAuth);

   BloggerService blogService = new BloggerService(new BaseClientService.Initializer()
   {
    Authenticator = auth,
    ApplicationName = "BloggerTest"
   });

   BlogsResource.GetByUrlRequest getReq = blogService.Blogs.GetByUrl(blogUrl);
   getReq.Key = apiKey;
   Blog blog = getReq.Execute();
   Console.WriteLine(blog.Id);

   Console.ReadKey();

  }

  private static IAuthorizationState getAuth(NativeApplicationClient arg)
  {
   IAuthorizationState state = new AuthorizationState(new[] { BloggerService.Scopes.Blogger.GetStringValue() })
    {
     Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl)
    };
   Uri authUri = arg.RequestUserAuthorization(state);
   Process.Start(authUri.ToString());
   Console.WriteLine("Please enter auth code:");
   string authCode = Console.ReadLine();
   return arg.ProcessUserAuthorization(authCode, state);
  }
 }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用Google.api.Blogger.v3;
使用Google.api.Blogger.v3.Data;
使用Google.api.Services;
使用系统诊断;
使用Google.api.Authentication.OAuth2;
使用Google.api.Authentication.OAuth2.DotNetOpenAuth;
使用DotNetOpenAuth.OAuth2;
使用Google.api.Util;
命名空间测试
{
班级计划
{
静态void Main(字符串[]参数)
{
字符串apiKey=“{API-KEY}”;
字符串blogUrl=“{BLOG-URL}”;
字符串clientID=“{CLIENT_ID}”;
字符串clientSec=“{CLIENT_SECRET}”;
NativeApplicationClient provider=新的NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier=clientID,
ClientSecret=clientSec
};
OAuth2Authenticator auth=新的OAuth2Authenticator(提供者,getAuth);
BloggerService blogService=new BloggerService(new BaseClientService.Initializer())
{
Authenticator=auth,
ApplicationName=“BloggerTest”
});
BlogsResource.GetByUrlRequest getReq=blogService.Blogs.GetByUrl(blogUrl);
getReq.Key=apiKey;
Blog Blog=getReq.Execute();
Console.WriteLine(blog.Id);
Console.ReadKey();
}
私有静态IAAuthorizationState getAuth(NativeApplicationClient参数)
{
IAAuthorizationState=new AuthorizationState(新[]{BloggerService.Scopes.Blogger.GetStringValue()})
{
回调=新Uri(NativeApplicationClient.OutOfBandCallbackUrl)
};
Uri authUri=arg.RequestUserAuthorization(状态);
Process.Start(authUri.ToString());
Console.WriteLine(“请输入验证代码:”);
字符串authCode=Console.ReadLine();
返回参数ProcessUserAuthorization(authCode,state);
}
}
}
它有两个错误:

  • “Google.API.Services.BaseClientService.Initializer”不包含“Authenticator”的定义
  • “Google.api.Blogger.v3.BloggerService”不包含“范围”的定义
  • 你能帮我修一下吗。多谢各位


    我的代码来自:

    在实现Google API时,初学者面临两个常见问题。这都是由于API库不稳定,以及从一个版本到下一个版本的变化

  • 当API更改时,示例应用程序不会更改。因此,开发人员试图在最新的API中使用过时的代码

  • 指向旧版本API库的链接不会被清除。因此,开发人员可以下载旧库

  • 所以1和2有点相反,但两者都发生了。问题1更常见


    因此,在本例中,请检查您是否下载了最新版本的API库,并检查丢失的定义是否已被撤回,在这种情况下,您需要找到一个更为最新的示例。

    您是否能够修复它?我也有同样的问题。