相关疑难解决方法(0)

Google+ API:如何在每次启动应用时使用RefreshTokens来避免请求访问权限?

我正在尝试使用Google+ API访问经过身份验证的用户的信息.我已从其中一个示例中复制了一些代码,这些代码工作得很好(下图),但是我无法以一种可以在应用程序启动时重用令牌的方式工作.

我尝试捕获"RefreshToken"属性并使用provider.RefreshToken()(除其他外)并始终得到400 Bad Request响应.

有谁知道如何使这项工作,或知道我在哪里可以找到一些样品?在谷歌代码网站似乎并没有涵盖这:-(

class Program
{
    private const string Scope = "https://www.googleapis.com/auth/plus.me";

    static void Main(string[] args)
    {
        var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
        provider.ClientIdentifier = "BLAH";
        provider.ClientSecret = "BLAH";
        var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);

        var plus = new PlusService(auth);
        plus.Key = "BLAH";
        var me = plus.People.Get("me").Fetch();
        Console.WriteLine(me.DisplayName);
    }

    private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
    {
        // Get the auth URL:
        IAuthorizationState state = new AuthorizationState(new[] { Scope });
        state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); …
Run Code Online (Sandbox Code Playgroud)

.net c# google-api dotnetopenauth google-plus

23
推荐指数
2
解决办法
2万
查看次数

如何使用access_token创建CalendarService对象?

我正在尝试使用.net客户端使用谷歌日历v3 api.我正在采用混合方法.我只使用http post请求使用oauth2授权我的应用程序,我得到了access_token.但作为日历v3 api的.net客户端,我需要制作一个日历服务参考.我需要找到任何方法来使用我的令牌获取该服务引用.看看这段代码:

Event event = new Event()
{
  Summary = "Appointment",     
};

Event recurringEvent = service.Events.Insert(event, "primary").Fetch();
// here "service" is authenticate calendarservice instance.

Console.WriteLine(recurringEvent.Id);
Run Code Online (Sandbox Code Playgroud)

这是获取经过身份验证的日历服务实例的代码:

 UserCredential credential;
 using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
 {
      credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[] { CalendarService.Scope.Calendar },
                "user", CancellationToken.None, new FileDataStore("something"));
 }

  // Create the service instance.
  var service = new CalendarService(new BaseClientService.Initializer()
  {
          HttpClientInitializer = credential,
          ApplicationName = "Books API Sample",
  });
Run Code Online (Sandbox Code Playgroud)

此代码根据Google.Apis.Auth.OAuth2显示授权代码流,然后使用该凭据进行服务引用.实际上,这是一个管理授权代码流的辅助工具.为了清楚起见,我没有使用这个程序.(这个助手实用程序).我正在尝试在核心级别执行所有操作,这意味着我已通过简单的HTTP Web请求手动创建了授权代码流.我完全完成了授权.现在我有那个用户access_token.

现在我的问题是如何仅使用该access_token手动创建此服务实例.如果有什么事打扰你,请随时提出任何问题.

注意 - 我知道如何创建CalendarService实例: …

google-calendar-api oauth-2.0 google-api-dotnet-client

6
推荐指数
2
解决办法
2164
查看次数

使用刷新令牌进行 C#sharp 身份验证的 Google.Apis 客户端

我正在使用适用于 .NET 的新测试版 Google API 客户端库来加载多个用户的任务列表。它被归类为“已安装的应用程序”(根据谷歌开发控制台),具有多个授权用户帐户。验证一个用户的身份非常简单(使用 google.apis),但我不知道如何使用刷新令牌执行相同的操作,以及如何使用此令牌来获取服务对象。

示例代码:

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(GoogleTools.GenerateStreamFromString(GoogleTools.Cred)).Secrets,
new[] { TasksService.Scope.Tasks },
"user", CancellationToken.None, new FileDataStore("Tasks.Auth.Store")).Result;         


// Create the service.
service = new TasksService(new BaseClientService.Initializer()
{
     HttpClientInitializer = credential,
     ApplicationName = "Tasks API Sample",
});
Run Code Online (Sandbox Code Playgroud)

我想credential使用刷新令牌构造对象,但我真的迷失了,找不到任何合适的文档。

c# google-api oauth-2.0 google-api-dotnet-client

3
推荐指数
1
解决办法
6101
查看次数

如何创建具有访问权限和Google Drive API令牌的凭证对象

我想对工作表和Google驱动器api使用相同的OAuth代码和令牌,而无需将工作表和驱动器重定向到第2页。

以下是使用oauth 2生成访问代码和令牌的代码

                string SCOPE = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds";
                OAuth2Parameters parameters = new OAuth2Parameters();
                parameters.ClientId = CLIENT_ID;
                parameters.ClientSecret = CLIENT_SECRET;
                parameters.RedirectUri = REDIRECT_URI;
                parameters.Scope = SCOPE;
                string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); 
                OAuthUtil.GetAccessToken(parameters);
                string accessToken = parameters.AccessToken;
Run Code Online (Sandbox Code Playgroud)

就像在asp.net mvc中一样,它是通过重定向Google表格API生成的。

我也想使用Google Drive API来获得相同的令牌。

我如何才能为Google Drive API 创建凭据对象,以便与其一起使用。遵循代码打开另一个窗口并将代码发送到该窗口。

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
      {
         ClientId = clientId,
         ClientSecret = clientSecret
      }, scopes, "skhan", CancellationToken.None, new FileDataStore("Drive.Auth.Store")).Result;
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc oauth google-drive-api google-api-dotnet-client

1
推荐指数
1
解决办法
1613
查看次数