Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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# Google使用服务帐户json c联系access#_C#_Asp.net_Json_Oauth 2.0_Google Contacts Api - Fatal编程技术网

C# Google使用服务帐户json c联系access#

C# Google使用服务帐户json c联系access#,c#,asp.net,json,oauth-2.0,google-contacts-api,C#,Asp.net,Json,Oauth 2.0,Google Contacts Api,我正在尝试使用OAuth 2.0访问我的Google联系人,用于ASP.net MVC应用程序中的服务器到服务器应用程序,但在尝试检索令牌时遇到一些问题。“test-470272c3a5fa.json”是我从GoogleAPI控制台下载的文件,目前在我的桌面上。有什么想法吗 这是我的密码: public class GoogleContactsApiInterface { public GoogleContactsApiInterface() { ServiceA

我正在尝试使用OAuth 2.0访问我的Google联系人,用于ASP.net MVC应用程序中的服务器到服务器应用程序,但在尝试检索令牌时遇到一些问题。“test-470272c3a5fa.json”是我从GoogleAPI控制台下载的文件,目前在我的桌面上。有什么想法吗

这是我的密码:

public class GoogleContactsApiInterface
{
    public GoogleContactsApiInterface()
    {
        ServiceAccountCredential serviceAccountCredential;
        string[] scopes = { "https://www.google.com/m8/feeds/" };
        string keyPath = "C:\\Users\\55122545\\Desktop\\test-470272c3a5fa.json";

        using (var stream = new FileStream(keyPath, FileMode.Open, FileAccess.Read))
        {
            serviceAccountCredential =  GoogleCredential.FromStream(stream)
                                                        .CreateScoped(scopes)
                                                        .UnderlyingCredential as ServiceAccountCredential;

            OAuth2Parameters parameters = new OAuth2Parameters();
            parameters.AccessToken  = serviceAccountCredential.Token.AccessToken;
            parameters.RefreshToken = serviceAccountCredential.Token.RefreshToken;

            RequestSettings rs = new RequestSettings("testApp", parameters);
            rs.AutoPaging = true;

            ContactsRequest cr = new ContactsRequest(rs);

            Feed<Contact> f = cr.GetContacts();

            foreach (Contact c in f.Entries)
            {
                //do something
            }

        }
    }
}
公共类GoogleContactsAPI接口
{
公共谷歌联系人SapiInterface()
{
ServiceAccountCredential ServiceAccountCredential;
字符串[]作用域={”https://www.google.com/m8/feeds/" };
string keyPath=“C:\\Users\\55122545\\Desktop\\test-470272c3a5fa.json”;
使用(var stream=newfilestream(keyPath,FileMode.Open,FileAccess.Read))
{
serviceAccountCredential=GoogleCredential.FromStream(流)
.CreateScoped(范围)
.作为ServiceAccountCredential的基础凭证;
OAuth2Parameters参数=新的OAuth2Parameters();
parameters.AccessToken=serviceAccountCredential.Token.AccessToken;
parameters.RefreshToken=serviceAccountCredential.Token.RefreshToken;
RequestSettings rs=新的RequestSettings(“testApp”,参数);
rs.autopage=true;
ContactsRequest cr=新的ContactsRequest(rs);
Feed f=cr.GetContacts();
foreach(f.条目中的联系人c)
{
//做点什么
}
}
}
}