1

AndroidでGoogle Places APIを使用して自分の場所を追加したい次のコードスニペットを使用していますが、この例外が発生します:

com.google.api.client.http.HttpResponseException: 400 不正な要求

私のコードスニペットは次のとおりです。

private static final String PLACE_ADD_URL = "https://maps.googleapis.com/maps/api/place/add/json?"; 
public PlacesList addPlace() throws Exception {

try {
        Log.v(LOG_KEY, "Adding Place...");
        GenericUrl reqUrl = new GenericUrl(PLACE_ADD_URL);
        reqUrl.put("key", API_KEY);
        reqUrl.put("sensor", "false");
        Log.v(LOG_KEY, "Adding Place...");
        //reqUrl.put("Host:", "maps.googleapis.com");
        reqUrl.put("Host: maps.googleapis.com","{\"location\":{\"lat\":-33.8733721,\"lng\":151.2012871},\"accuracy\":50.0,\"name\":\"harbour\",\"types\":[\"food\"],\"language\":\"en\"}");
        Log.v(LOG_KEY, "Requested URL= " + reqUrl);

        HttpRequestFactory httpRequestFactory = createRequestFactory(transport);
        HttpRequest request = httpRequestFactory.buildGetRequest(reqUrl);


        Log.v(LOG_KEY, request.execute().parseAsString());  
        PlacesList place = request.execute().parseAs(PlacesList.class);

        Log.v(LOG_KEY, "STATUS = " + place.status); 
        Log.v(LOG_KEY, "Place Added is = " + place);    

            return place;

    } catch (HttpResponseException e) {
        Log.v(LOG_KEY, e.getResponse().parseAsString());
        throw e;
    }

    catch (IOException e) {
        // TODO: handle exception
        throw e;
    }
}  

今、私はこの例外で多くのことをしましたが、解決できません。このリクエスト URL をどのように渡す必要がありますか? 私のアプローチは正しいですか、それとも間違っていますか??

4

1 に答える 1

0

キーをnullとして返していました。今、私は正しいキーを渡し、正常に動作します

于 2012-03-14T15:58:30.987 に答える