在maps.googleapis.com上调用401错误

时间:2016-06-03 16:53:41

标签: google-maps google-api

我在调用maps.googleapis.com时遇到401错误,但我对此感到困惑。我希望有人可以指出我做错了什么。

在服务器上,我有一个包含此代码的函数:

private string DoGoogleWork(string address) {
    string GoogleServerAPIKey = "My Server API key";
    string strXML = string.Empty;
    using(WebClient c = new WebClient()){
         var geoCodeUrl = "https://maps.googleapis.com/maps/api/geocode/xml?address=" + addr.Replace(' ', '+') + "&key=" + GoogleServerAPI;
         try
         {
             strXML = c.DownloadString(geoCodeUrl); // raises a 401 exception
         }
         catch (Exception ex)
         {
             ErrorLogger(ex.Message);
         }
    }

    //
    // Parse the XML and do some work with the results
    //
}

我的服务器API密钥没有IP限制,所以我不确定为什么我会收到401错误。我希望有人能看到我失踪的东西。

TIA!

1 个答案:

答案 0 :(得分:0)

错误401表示Invalid authorization header。您正在使用的访问令牌已过期或无效。使用长期刷新令牌刷新访问令牌。如果此操作失败,请引导用户完成OAuth flow,您需要获取新的身份验证令牌。

检查此相关thread