C# Google使用服务帐户json c联系access#
我正在尝试使用OAuth 2.0访问我的Google联系人,用于ASP.net MVC应用程序中的服务器到服务器应用程序,但在尝试检索令牌时遇到一些问题。“test-470272c3a5fa.json”是我从GoogleAPI控制台下载的文件,目前在我的桌面上。有什么想法吗 这是我的密码: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
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)
{
//做点什么
}
}
}
}