我需要一些帮助 - 我仍然在使用Directory API围绕新的Google Admin SDK。到目前为止,我能够创建/删除用户,创建/删除别名。我已授权我需要的那些领域的范围等。
我的问题是如何使用下面的现有代码才能使用GData库?我需要使用" CreateSendAs()"功能,但使用与目录API不同的另一组包含。我是否必须将Auth2.0令牌设置为某种东西,以便我可以使用旧的GData调用?
我用于目录API:
const string serviceAccountEmail = "XXXXXX@developer.gserviceaccount.com";
const string serviceAccountCertPath = @"C:\XX-privatekey.p12";
const string serviceAccountCertPassword = "notasecret";
const string userEmail = "super-admin-user@domain.com";
var certificate = new X509Certificate2(serviceAccountCertPath, serviceAccountCertPassword, X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser },
User = userEmail
}.FromCertificate(certificate));
var service = new DirectoryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = APP_NAME,
});
这是我需要用于" CreateSendAs()"功能
using Google.GData.Apps;
using Google.GData.Apps.GoogleMailSettings;
using Google.GData.Client;
using Google.GData.Extensions;
GoogleMailSettingsService service = new GoogleMailSettingsService("yourdomain", "your-apps");
service.setUserCredentials("adminUsername", "adminPassword");
service.CreateSendAs("liz", "Sales", "sales@example.com", "", "true");
答案 0 :(得分:0)
我不确定以下方法有多正确,但这对我有用。使用服务凭证令牌,您可以按如下方式访问GoogleMailSettingsService
bool success = credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result;
OAuth2Parameters parameter = new OAuth2Parameters()
{
AccessToken = credential.Token.AccessToken
};
GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory("apps","your-apps", parameter);
GoogleMailSettingsService service = new GoogleMailSettingsService("yourdomain", "your-apps");
service.RequestFactory = requestFactory;
service.CreateSendAs("liz", "Sales", "sales@example.com", "", "true");