如何修复Google地图“服务器上的身份验证失败”? [英] How to fix Google Maps "Authentication failed on the server"?

查看:1453
本文介绍了如何修复Google地图“服务器上的身份验证失败”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打印了我的SHA1密钥:

  keytool -list -v -keystore keystore.jks 

code>

在Google控制台中生成了一个API密钥,

更新了清单文件如下所示:

 < meta-data android:name =com.google.android.gms.version
android:value =@ integer / google_play_services_version/>
< meta-data
android:name =com.google.android.maps.v2.API_KEY
android:value =AIzaSyC1YOsomestringsarehiddedLu5_TnCxlyuRM/>

然后我创建了一个简单的 Activity Google样本:

  public class MapActivity扩展FragmentActivity实现的OnMapReadyCallback {

@Override
保护void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.map_sample);

SupportMapFragment mapFragment =
(SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap map){
map.addMarker(new MarkerOptions()。position(new LatLng(0,0)) .title伪( 标记));
}

}

当然,我在Manifest文件中添加了这个活动。

 确保以下Android密钥存在:
API密钥:AIzaSyC1YOn9myapikeystringsxxu5_TnCxlyuRM
Android应用程序(< cert_fingerprint>;< package_name>):
B2:E8:75:4F:01:DD:xx:xx:xx:xx:xx:xx:74:A5:85:2C :A4:38:48; md.mycompany.catalog

奇怪的部分是SHA1键我在Google Console中粘贴的内容与上面的不一样。我再次尝试,它仍然显示另一个SHA1密钥。我甚至试过这个SHA1,但它仍然不起作用。

p.s。我有Youtube API集成在同一个应用程序中,并且所有东西都完美地工作,使用相同的KEY。

解决方案

从应用的发布版本构建密钥,但错误消息表明您正在本地测试,这也表明您正在使用APK的调试版进行测试。由于SHA1密钥与发布版本不同,您可以将两个密钥都保留在清单中,但在本地测试时注释版本密钥。像这样:





编辑(2016年4月28日) ) - 使用Android Studio并构建风格,考虑到您可以指定不同的字符串给定buildType(调试或发布)和风格,此技术是不必要的。我现在推荐 andorid:value =@ string / maps_v2_api_key,而不是硬编码。

  buildTypes {
版本{
resValue'string','maps_v2_api_key','123 .. .xyz'
}
debug {
resValue'string','maps_v2_api_key',''345 ... vut''
}
}


I have printed my SHA1 key:

keytool -list -v -keystore keystore.jks

generated an API key in Google Console,

updated the manifest file as follows:

<meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyC1YOsomestringsarehiddedLu5_TnCxlyuRM"/>

Then I created a simple Activity as in Google Samples:

public class MapActivity extends FragmentActivity implements OnMapReadyCallback {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_sample);

    SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap map) {
    map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}

}

And of course I added the activity inside Manifest file. I always get the same error.

Ensure that the following Android Key exists:
API Key: AIzaSyC1YOn9myapikeystringsxxu5_TnCxlyuRM
Android Application (<cert_fingerprint>;<package_name>):
B2:E8:75:4F:01:DD:xx:xx:xx:xx:xx:xx:74:A5:85:2C:A4:38:48;md.mycompany.catalog

The strange part is that the SHA1 key which I pasted in Google Console is not the same as the one above. I tried again, and it still shows another SHA1 key. I even tried this SHA1 and still it does not work.

p.s. I have Youtube API integrated in same app, and everything works perfectly, with same KEY.

解决方案

From the comments you stated that you built the key from the Release version of the app, but the error message suggests that you were testing locally which would also suggest that you're testing with the debug version of your APK.

Since the SHA1 key differs from release to debug, you can keep both keys in your manifest but comment out the release version key while testing locally. Like so:

Edit (April 28 2016) - With Android Studio and build flavors, this technique is unnecessary considering you can point to different strings given a buildType (debug or release) and flavor. I would now recommend andorid:value="@string/maps_v2_api_key" instead of hard coding as such.

buildTypes {
   release {
    resValue 'string', 'maps_v2_api_key', '"123...xyz"'
   }
   debug {
    resValue 'string', 'maps_v2_api_key', '"345...vut"'
   }
}

这篇关于如何修复Google地图“服务器上的身份验证失败”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆