2013-05-07 3 views
0

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; 
+0

특정 범위에 앱을 등록 했습니까? 앱이 등록되지 않은 범위의 액세스 토큰을 요청할 수 없습니다. – divyanshm

답변

0

을 당신은 올바른 API를 사용하고 있습니다. GData가 새로운 Google API로 대체 되긴하지만 Admin Settings API는 여전히 이전 GData 형식을 사용합니다.

인증에 수퍼 관리자 계정을 사용하고 있습니까? OAuth 2.0 playground에서 작업을 시도해보고 해당 계정에서 제대로 작동하는지 확인하십시오.

오픈 소스 Google Apps 도구 인 Dito GAMthis call을 구현하는 방법을 살펴볼 수도 있습니다. debug.gam이라는 파일을 GAM과 동일한 경로에 생성하면 GAM은 모든 원시 HTTP 호출과 응답을 출력합니다.

+0

감사합니다. OAuth 2.0 놀이터는 내 요청의 유효성을 확인하는 데 도움이되고 예는 최고 관리자 권한을 가졌습니다. – Francis

관련 문제