2017-04-13 2 views
0

좋아요, Microsoft "Professional Support"와 채팅 한 후 그들은 나를 도울 수 없었습니다. SfB Report GUI를 통해 보고서에 액세스하고 Excel로 내보낼 수 있다고 알려 주셨습니다.그래프 API를 통해 Skype for Business 활동을 끌어 오려고 할 때 오류 400 잘못된 요청

네, 그건 완전히 쓸모가 없습니다. 더 많은 독서를 한 후에, 나의 첫 번째 예는 인증이 오래되었습니다.

이제는 유효한 토큰을 얻는 완전한 기능을 갖춘 oAuth2 PowerShell 스크립트가 있습니다.

그러나 Graph Explorer (403 Forbidden)를 사용할 때 같은 문제가 발생합니다. GET 헤더에서 토큰에 대한 VAR을 제거하면 베어러 토큰이 비어있어 모든 것이 옳다는 오류가 표시되므로 다른 정보를 쿼리 할 수 ​​있기 때문에 토큰이 작동하고 있음을 알고 있습니다. SCRIPT 업데이트]

Microsoft, if you're out there can someone please confirm that the SfB Report API is up and running for the statistics I'm attempting to pull?

#Obtaining oAuth2 Token from Microsoft Azure \ communicate with Microsoft Graph API 
 

 
$ClientID = "MyID" 
 
$client_Secret = "MySecretKey" 
 

 
#Define URI for Azure Tenant 
 
$Uri = "https://login.microsoftonline.com/MyTenantID/oauth2/token" 
 

 
#Define Microsoft Graph - Skype for Business reports interface URI 
 
$exportSfB = "https://graph.microsoft.com/beta/reports/SfbActivity(view='Detail',date='2017-04-11')/content" 
 

 
#Define the body of the request 
 
$Body = @{grant_type='client_credentials';client_id=$ClientID;client_secret=$client_secret;resource='https://graph.microsoft.com'} 
 

 
#Define the content type for the request 
 
$ContentType = "application/x-www-form-urlencoded" 
 

 
#Invoke REST method. This handles the deserialization of the JSON result. Less effort than invoke-webrequest 
 
$admAuth=Invoke-RestMethod -Uri $Uri -Body $Body -Method Post 
 

 
#Construct the header value with the access_token just recieved 
 
$HeaderValue = "Bearer " + $admauth.access_token 
 

 
#Query Microsoft Graph with new Token 
 
$result = Invoke-RestMethod -Headers @{Authorization=$HeaderValue} -Uri $exportSfB –Method Get -Verbose 
 

 
#Results should be a .CSV 
 
$result.string.'#text'

ORIGINAL THREAD 사람이 REST의 코드를 살펴 가지고시겠습니까 날 그들이 어떻게 생각하는지 말해?

나는 수신 해요 :

는 호출-RestMethod은 : (400) 잘못된 요청 : 원격 서버에서 오류를 반환했습니다.

  • CategoryInfo : InvalidOperation는

나는 그래프를 사용하여 비즈니스 활동 보고서에 대해 하나의 Skype를 당길 수 없었다.

$tenant = "MyTenant.onmicrosoft.com" 
 

 
function GetAuthToken 
 
{ 
 
     param 
 
     (
 
       [Parameter(Mandatory=$true)] 
 
       $TenantName 
 
     ) 
 
    
 
     $adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" 
 
    
 
     $adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" 
 
    
 
     [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null 
 
    
 
     [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null 
 
    
 
     $clientId = "MyID" 
 
    
 
     $redirectUri = "urn:ietf:wg:oauth:2.0:oob" 
 
    
 
     $resourceAppIdURI = "https://graph.microsoft.com/" 
 
    
 
     $authority = "https://login.windows.net/$TenantName" 
 
    
 
     $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority 
 
    
 
     $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId,$redirectUri, "Auto") 
 
    
 
     return $authResult 
 
} 
 

 

 
# Set Token var 
 

 
$token = GetAuthToken -TenantName $tenant 
 

 
# Building Rest Api header with authorization token 
 
$authHeader = @{ 
 
    'Content-Type'='application\json' 
 
    'Authorization'=$token.CreateAuthorizationHeader() 
 
} 
 

 
$uri = "https://graph.microsoft.com/beta/reports/SfbActivity(view='Detail',date='2017-04-11')" 
 

 
$output = (Invoke-RestMethod -Uri $uri –Headers $authHeader –Method Get –Verbose).value

답변

1

당신은 당신의 URI에 /content을 놓치고있어. doc here을 참조하십시오.

$uri = "https://graph.microsoft.com/beta/reports/SfbActivity(view='Detail',date='2017-04-11')/content" 
+0

불행히도 문제가 해결되지 않았지만 좋은 캐치 . Microsoft Graph Explorer를 사용하여 작동시키지 못했습니다. 나는 그것에 대해 마이크로 소프트에게 열리는 티켓을 가지고있다. 내가 베타에 있다는 것을 알았지 만 그 통계를 끌어 내야 할 필요가 있습니다. – CWB

+0

현재 그래프 탐색기가 작동하지 않을 수 있습니다. 나는 그것이 Reports.Read.All 범위를 요청할 것이라고 믿지 않기 때문에 단지 403 오류를 다시 걷어 찰 것이다. –

+0

안녕하세요. Marc,보고 용 SfB API에 액세스 할 수 있는지 확인해주세요. – CWB

0

그렇다면 API를 잘못 읽고 처음부터 다시 시작하기로 결정했습니다. 전체 시간이 Azure의 App 유형 인 경우 문제가 발생합니다. 나는 누군가가 프로젝트를 맡기 전에 내가 만든 앱을 사용하고 있었다. 응용 프로그램 유형이 Azure에서 "Web \ API"로 설정되었는데 이는 분명히 잘못되었습니다. "Native"응용 프로그램 유형으로 새 응용 프로그램을 만들었습니다. 새 암호 액세스 키와 응용 프로그램 클라이언트 ID로 코드를 변경했기 때문에 .csv 파일을 가져올 수있었습니다. 문제는 현재 PSTN 데이터가 존재하지 않는다는 것입니다. GitHub에서이 문제를 알고 있는지 여부를 묻는 Microsoft Graph 그룹의 티켓을 만들었습니다. 현재 API를 통해 PSTN 통화 세부 정보를 내보내는 프로그램 방식을 찾을 수 없습니다. 해당 요청에 대한 진행 상황을 계속 관찰 할 수 있지만 Microsoft Dev가 SfBActivity 세부 정보 보고서에 해당 데이터 필드를 포함시킬 때까지 붙어 있습니다. https://github.com/microsoftgraph/microsoft-graph-docs/issues/1133