【发布时间】:2019-02-03 13:36:45
【问题描述】:
我正在尝试使用 Google Streetview Static API 来获取大量街景图像。我有一个有效的 API 密钥和 URL 签名密钥,但我在对签名进行编码时遇到了问题。无论我尝试了什么,我都会得到错误的签名,并且 url 不起作用。任何帮助将不胜感激。
这是我所做的(Encode方法不是我的):
static void Main(string[] args)
{
Process.Start(GenerateURL(0, 0, "40.7488115", "-73.9855688", 1920, 1080, 90));
Console.ReadLine();
}
public static string GenerateURL(double heading, double pitch, string locationLat, string locationLong, int resX, int resY, int fov)
{
string universalURL = "size=" + resX + "x" + resY + "&location=" + locationLat + "," + locationLong + "&heading=" + heading + "&pitch=" + pitch + "&fov=" + fov + "&key=" + apiKey;
string getURL = "https://maps.googleapis.com/maps/api/streetview?" + universalURL;
string getSignature = "_maps_api_streetview?" + universalURL;
return getURL + "&signature=" + Encode(getSignature, signingKey);
}
public static string Encode(string input, string inputkey)
{
byte[] key = Encoding.ASCII.GetBytes(inputkey);
byte[] byteArray = Encoding.ASCII.GetBytes(input);
using (var myhmacsha1 = new HMACSHA1(key))
{
var hashArray = myhmacsha1.ComputeHash(byteArray);
return hashArray.Aggregate("", (s, e) => s + String.Format("{0:x2}", e), s => s);
}
}
我使用 _ 而不是 / 作为 getSignature 的原因是因为 here 它说它需要被替换。我已经尝试过使用 / 但它不起作用。
感谢您的帮助。
【问题讨论】:
标签: c# google-api google-street-view