Google Apps 도메인의 조직 이름을 가져 오려고합니다. 이를 위해 Google Apps 관리자 설정 API를 사용하고 있습니다. 3-Legged OAuth가 필요하다는 것을 알았습니다. OAuth 1은 사용되지 않으므로 OAuth 2.0을 구현하려고합니다. 나는이 일을하기 위해 많은 일을 시도하지만 나는 항상 401을 얻지 못하고있다. Google Apps 관리자 설정 API - 401
나는 범위에 대한 토큰을 요청 : https://apps-apis.google.com/a/feeds/domain/ 여기것은 내 코드입니다 :
// ClientID & ClientSecret values
var requestFactory = GDAPI.GoogleApps.GetAuthRequestFactory();
string organizationName = String.Empty;
Google.GData.Apps.AdminSettings.AdminSettingsService service =
new Google.GData.Apps.AdminSettings.AdminSettingsService(auth.Domain, Excendia.Mobility.Utilities1.BLL.WebConfig.ExcendiaAppName);
service.RequestFactory = requestFactory;
service.SetAuthenticationToken(token);
try
{
var result = service.GetOrganizationName(); // throw exception here...
}
catch (Exception ex)
{
log.Error(ex);
}
내가 무슨 일을하고 있는가? OAuth 2와 호환 가능합니까?
나는 또한의 GData 라이브러리가 사용되지 않는 새로운 Google.Apis로 대체 있어야하기 때문에 조직 이름을 얻을 수있는 또 다른 방법이 있는지 물어보고 싶은 ...
는 해결!
감사합니다. Jay. OAuth 2.0 놀이터에서 작동합니다. 내 편이 올바르게 설정되지 않았습니다.
피들러를 사용하여 인증 헤더가 내 애플리케이션에서 설정되는 것을 보았습니다. v2 대신 OAuth v1로 설정되었습니다. 그래서 잘못된 RequestFactory 클래스를 사용하고 있음을 알았습니다. 그래서 지금 노력하고 있습니다 ... 대신 GOAuthRequestFactory의 GOAuth2RequestFactory를 사용하는
필요 :
string organizationName = String.Empty;
Google.GData.Apps.AdminSettings.AdminSettingsService service =
new Google.GData.Apps.AdminSettings.AdminSettingsService(auth.Domain, "myAppName");
service.RequestFactory =
new Google.GData.Client.GOAuth2RequestFactory("cl", "MyAppName",
new Google.GData.Client.OAuth2Parameters()
{ ClientId = ClientID,
ClientSecret = ClientSecret,
AccessToken = token });
try
{
var result = service.GetOrganizationName();
if (result != null)
{
organizationName = result.OrganizationName;
}
}
catch (Exception ex)
{
log.Error(ex);
}
return organizationName;
특정 범위에 앱을 등록 했습니까? 앱이 등록되지 않은 범위의 액세스 토큰을 요청할 수 없습니다. – divyanshm