2

Bingmaps API を使用して、緯度と経度の AdminDistrict と CountryRegion を取得しています。ブラウザに次の URL を入力すると機能します。

http://dev.virtualearth.net/REST/v1/Locations/-30,-70/?includeEntityTypes=AdminDivision1,CountryRegion&o=xml&c=es-ES&key= myBingmapsApiKey

しかし、WP7 の C# では動作しません。これはコードです:

string wsUrl = "http://dev.virtualearth.net/REST/v1/Locations/-30,-70/?includeEntityTypes=AdminDivision1,CountryRegion&o=xml&c=es-ES&key=*myBingmapsApiKey*";

var request = new RestSharp.RestRequest(Method.GET);
var client = new RestSharp.RestClient(wsUrl);

try
{
    RestSharp.RestResponse resource;
    client.ExecuteAsync(request, (response) =>
    {
        resource = response;
        string content = resource.Content;
        string status_code = resource.StatusCode.ToString();
        string response_status = resource.ResponseStatus.ToString();
    });
}
catch (Exception e)
{
    string error = "Error: " + e.ToString() + "\n. Stack Trace: " + e.StackTrace;
}

そして、応答は次のとおりです。

    <?xml version="1.0" encoding="utf-8"?>
    <Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">
<Copyright>Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
<BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>
<StatusCode>401</StatusCode><StatusDescription>Unauthorized</StatusDescription>
<AuthenticationResultCode>InvalidCredentials</AuthenticationResultCode>
<ErrorDetails><string>Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation.</string></ErrorDetails>
<TraceId>59ebcf604bb343d79a6e8b93ad5695fe|MIAM001452|02.00.71.1600|</TraceId>
<ResourceSets />
    </Response>

URL は Web ブラウザで動作しているものと同じです。何が間違っている可能性がありますか?

4

2 に答える 2

3

おそらくこの時点ですでに解決策を思いついていますが、Googleで検索するとこのトピックが見つかりました。解決策は、あなたがやっているようにURLを介してキーを送信せず、代わりに次のようにリクエストにパラメータとして追加することです:

string wsUrl = "http://dev.virtualearth.net/REST/v1/Locations/-30,-70/";    

var request = new RestSharp.RestRequest(Method.GET);    
request.AddParameter("includeEntityTypes", "AdminDivision1,CountryRegion");
request.AddParameter("key", myLey);
request.AddParameter("o", "xml");
于 2011-12-14T19:52:53.240 に答える
0

私がこれを正しく理解していれば、使用する REST API には費用がかかる可能性があります。API キーが請求可能なトランザクション用に設定されていない可能性がありますか?

このページには、Location API の課金について次のように記載されています。

*このカテゴリは、AJAX コントロールまたは Silverlight コントロール セッションのコンテキスト内で発生した場合、課金対象外です。

おそらく、ブラウザは AJAX コントロールとしてカウントされ、電話は正確には「Silverlight コントロール」ではありません。

于 2011-11-24T23:19:43.323 に答える