0
Я приложение Google для работы администратора,Google Contacts API OAuth2 Выпуск
я являюсь сервер программы для серверного приложения, чтобы получить информацию контактов из моей учетной записи домена,
и я могу получить контакты информацию самостоятельно ,
, но я получаю ошибку кода 403, когда я обращаюсь к своим пользователям учетной записи домена.
Это мой код:
public class BESGoogleContactsService
{
private const string serviceAccountEmail = "[email protected]";
private const string serviceAccountCertPath = "BesSSO-123123.p12";
private const string serviceAccountCertPassword = "notasecret";
private const string adminEmail = "[email protected]";
public BESGoogleContactsService()
{
var certificate = new X509Certificate2(serviceAccountCertPath, serviceAccountCertPassword, X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { "https://www.google.com/m8/feeds/" },
User = adminEmail
}.FromCertificate(certificate));
bool success = credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result;
RequestSettings settings =
new RequestSettings("Google Sync.", credential.Token.AccessToken)
{
AutoPaging =true,
UseSSL = true
};
ContactsRequest cr = new ContactsRequest(settings);
PrintAllContacts(cr);
}
public static void PrintAllContacts(ContactsRequest cr)
{
Feed<Contact> feed = cr.GetContacts("[email protected]");
Console.WriteLine(feed.TotalResults);
foreach (Contact entry in feed.Entries)
{
Console.WriteLine(entry.Name.FullName);
}
}
}
может каждый помочь мне решить эту проблему?
403 запрещенная ошибка, есть некоторые ответы на него -http: //stackoverflow.com/questions/20372453/getting -a-403-forbidden-for-google-service-account – yogihosting
благодарю вас за ответы, но я добавил UserAccountEmail, у меня проблема с швом. – CHANGYU