Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用agsxmpp和oauth2连接到google talk?_C#_.net_Oauth 2.0_Google Talk_Agsxmpp - Fatal编程技术网

C# 如何使用agsxmpp和oauth2连接到google talk?

C# 如何使用agsxmpp和oauth2连接到google talk?,c#,.net,oauth-2.0,google-talk,agsxmpp,C#,.net,Oauth 2.0,Google Talk,Agsxmpp,我正在开发使用xmpp协议和GoogleTalk服务器的迷你聊天应用程序。我发现谷歌不允许连接到gtalk服务器,如果应用程序不可用的话。我正在寻找使用agsxmpp库连接到gtalk的代码,但找不到任何东西。关于google的oauth2协议的文档中有几个示例,展示了如何将google的API与oauth2一起使用。但是,据我所知,所有的例子都需要定义我们要连接的api。 如以下示例所示: using System; using System.IO; using System.Threadin

我正在开发使用xmpp协议和GoogleTalk服务器的迷你聊天应用程序。我发现谷歌不允许连接到gtalk服务器,如果应用程序不可用的话。我正在寻找使用agsxmpp库连接到gtalk的代码,但找不到任何东西。关于google的oauth2协议的文档中有几个示例,展示了如何将google的API与oauth2一起使用。但是,据我所知,所有的例子都需要定义我们要连接的api。 如以下示例所示:

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Books.v1;
using Google.Apis.Books.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;

namespace Books.ListMyLibrary
{
    /// <summary>
    /// Sample which demonstrates how to use the Books API.
    /// https://code.google.com/apis/books/docs/v1/getting_started.html
    /// <summary>
    internal class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Console.WriteLine("Books API Sample: List MyLibrary");
            Console.WriteLine("================================");
            try
            {
                new Program().Run().Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    Console.WriteLine("ERROR: " + e.Message);
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }

        private async Task Run()
        {
            UserCredential credential;
            using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
            {
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { BooksService.Scope.Books },
                    "user", CancellationToken.None, new FileDataStore("Books.ListMyLibrary"));
            }

            // Create the service.
            var service = new BooksService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Books API Sample",
                });

            var bookshelves = await service.Mylibrary.Bookshelves.List().ExecuteAsync();
            ...
        }
    }
}
它们指定了bookservice.Scope.Books,换句话说,它们显式地显示了要连接的服务。但谷歌的API列表中没有谷歌对话服务。因此,我对如何使用agsxmpp库和google的oauth2协议安全地连接到gtalk服务器感到困惑。
有人能给我举个例子说明如何做到这一点吗

这就是Google开发者中Google Talks文档的位置:

我相信,在未来它将被完全取代

您需要的谷歌对话范围是
https://www.googleapis.com/auth/googletalk

更多细节

用它替换books范围:

credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        new[] { "https://www.googleapis.com/auth/googletalk" },
                        "user", CancellationToken.None, new FileDataStore("Books.ListMyLibrary")); 

您可能还想更改文件数据存储…

谢谢您的回复!但我有一个问题:为什么我需要文件数据存储?它的用途是什么?“不实现XMPP的Hangouts”:源代码?这应该是一个无关紧要的问题,但我找不到正式的答案:((参见)。谷歌仍然有一个“开放通信”页面,它吹嘘“客户选择”,并以一种不会让它看起来死气沉沉的方式谈论XMPP。这离他们发布Hangouts应用程序只有6个月的时间了。@Nemo补充说Hangouts中缺少XMPP
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        new[] { "https://www.googleapis.com/auth/googletalk" },
                        "user", CancellationToken.None, new FileDataStore("Books.ListMyLibrary"));