2016-04-20 19 views
0

Azure ADグラフAPIを使用してユーザーthumbnailphotoを更新できるサンプルRESTクライアントを探していますか?取得するRESTクライアントがあり、それは私がこのサンプルJavaの残りのクライアントを試してみましたが、405を受信https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUserThumbnailPhotoAzure AD Graph APIを使用してサムネイル写真を更新するRESTクライアントサンプル?

に動作します - メソッド許可されていません:

public void updateUserPhotoGraph(ModelMap model) throws IOException { 

     //https://graph.windows.net/{tenant}/users/{user}/thumbnailPhoto?api-version=1.6 
     UriComponents uriComponents = getPhotoUri(); 
     String bearerToken = getBearerToken(); 

     try { 

      HttpClient httpclient = HttpClients.createDefault(); 
      byte[] bytesEncoded = Base64.encode(extractBytes()); 

      URIBuilder builder = new URIBuilder(uriComponents.toString()); 
      URI uri = builder.build(); 
      HttpPost request = new HttpPost(uri); 
      request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + bearerToken); 
      request.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM); 
      request.setEntity(new ByteArrayEntity(bytesEncoded)); 

      HttpResponse response = httpclient.execute(request); 
      HttpEntity entity = response.getEntity(); 
      if (entity != null) { 
       System.out.println(EntityUtils.toString(entity)); 
      } 
     } catch (Exception e) { 
      System.out.println(e.getMessage()); 
     } 
    } 

**にも送られたPATCH要求に上記を変更しましたが、得ました同じエラー。

誰でもこのAPIを使用してthumnailphotoを更新しましたか?
サムネイル写真の更新/設定に[https://graph.windows.net/ {テナント} /ユーザー/ {ユーザー} /thumbnailPhoto?api-version=1.6]を使用できますか?

これに適したAPIは何ですか?

答えて

0

this documentに見たとき、あなたは「thumbnailPhoto」プロパティは、ストリーム型であり、あなたがそのプロパティを更新するために、APIの下に使用しようとするので、PATCHを使用することができます見つけることができる:

https://graph.windows.net/{tenant}/directoryObjects/{user}/Microsoft.DirectoryServices.User/thumbnailPhoto?api-version=1.5 
+0

ご返信ありがとうございます。私はパッチを試しましたhttps://graph.windows.net/{tenent}/directoryObjects/{upn}/Microsoft.DirectoryServices.User/thumbnailPhoto?api-version=1.6 コンテンツタイプ:アプリケーション/オクテットストリーム バイト配列 GOT ----> {"odata.error":{"コード": "Request_BadRequest"、 "メッセージ":{"lang": "en"、 "value": "URI 'https: //graph.windows.net/{tenent}/directoryObjects/{upn}/Microsoft.DirectoryServices.User/thumbnailPhoto?api-version=1.6 'は名前付きストリームを参照し、' PATCH '操作には有効ではありません。 "}} }サムネイルはGETのみをサポートしているようです –

0

私がアップロードすることができましたURLへのPUT操作を使用したJpegサムネイル:https://graph.windows.net/{tenant}/users/{user object id}/thumbnailPhoto?api-version=1.6

コンテンツタイプヘッダーはapplication/octet-streamに設定する必要があります。コンテンツはバイナリJpegデータです。

私のコードはSwiftにありますのでここでは説明しませんが、この情報があれば、適切なJavaコードを作成するのは難しくありません。

1

上記の回答の助けを借りて、私はC#で動作する解決策を得ました。このメソッドは、次の変数を指定して呼び出すと機能します。

nuget:ADAL v2.19。

authContext =新しいAuthenticationContext( "https://login.microsoftonline.com/ "+テナント)

Globals.aadGraphResourceId =" https://graph.windows.net/"

資格=新しいClientCredential(のclientId、clientSecret)

API = "/ユーザ/" + objectId + "/ thumbnailPhoto"

希望すると助かります!

private async Task<string> UploadByteArray(string api, byte[] byteArray) 
{ 
     // NOTE: This client uses ADAL v2, not ADAL v4 
     AuthenticationResult result = authContext.AcquireToken(Globals.aadGraphResourceId, credential); 
     HttpClient http = new HttpClient(); 
     string url = Globals.aadGraphEndpoint + tenant + api + "?" + Globals.aadGraphVersion; 

     HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url); 
     request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);    
     request.Content = new System.Net.Http.ByteArrayContent(byteArray); 
     request.Content.Headers.Add("Content-Type", "application/octet-stream"); 
     HttpResponseMessage response = await http.SendAsync(request); 

     if (!response.IsSuccessStatusCode) 
     { 
      string error = await response.Content.ReadAsStringAsync(); 
      object formatted = JsonConvert.DeserializeObject(error); 
      throw new WebException("Error Calling the Graph API: \n" + JsonConvert.SerializeObject(formatted, Formatting.Indented)); 
     } 

     return await response.Content.ReadAsStringAsync(); 
    } 
関連する問題