2016-09-09 2 views
1

このコードは、JavaでPerson Groupを作成します。JavaのMicrosoft認知サービスのフェイスAPIエラー人グループを作成する

import java.net.URI; 
import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.client.utils.URIBuilder; 
import org.apache.http.impl.client.HttpClients; 
import org.apache.http.util.EntityUtils; 

public class JavaSample 
{ 
    public static void main(String[] args) 
    { 
     HttpClient httpclient = HttpClients.createDefault(); 

     try 
     { 
      URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/face/v1.0/persongroups/personGroupId"); 


      URI uri = builder.build(); 
      HttpPut request = new HttpPut(uri); 
      request.setHeader("Content-Type", "application/json"); 
      request.setHeader("Ocp-Apim-Subscription-Key", "mysubscriptionkey"); 


      // Request body 
      StringEntity reqEntity = new StringEntity("{body}"); 
      request.setEntity(reqEntity); 

      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()); 
     } 
    } 
} 

私はこのコードを実行すると、私はこのエラーを取る:それを修正するために

{"error":{"code":"BadArgument","message":"Request body is invalid."}}

は、私が何をすることができます。私はインターネット上のjavaを持つPerson Groupを作成するためのサンプルを見つけられなかったので、修正できません。

答えて

0

エラーが示唆しているように、HTTP要求本文の形式は、{body}です。

の本文のというセクションのAPIページをご覧ください。名前を指定する必要があり、オプションでユーザーデータを追加できます。

StringEntity reqEntity = new StringEntity("{" + 
    "\"name\":\"group1\"," + 
    "\"userData\":\"user-provided data attached to the person group\""+ 
"}") 

GitHub SDKページで追加のJavaの例が見つかります。

関連する問題