AndroidSha1限制API密钥失败
创始人
2024-10-10 02:00:27
0

API密钥基于Android应用程序的Sha1进行限制。如果在验证密钥时出现错误,请使用以下步骤解决问题:

  1. 打开Android Studio并打开项目。
  2. 在上方选择“Gradle”,然后展开项目并点击应用程序下的“任务”。
  3. 选择“android”并在应用程序级别上单击“signingReport”。
  4. 执行此命令后,您将获得应用程序的Sha1密钥。在Google API项目中添加此密钥。
  5. 更新应用程序的Manifest文件并使用新的API密钥。 以下是调用Google Places API时使用的代码示例:
private static final String API_KEY = "YOUR_API_KEY";

private static final String BASE_URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?";

public interface PlacesService {

    @GET(BASE_URL)
    Call getNearbyPlaces(
            @Query("key") String apiKey,
            @Query("location") String location,
            @Query("radius") int radius,
            @Query("type") String type);

}

public class PlacesApiClient {

    private static final String TAG = PlacesApiClient.class.getSimpleName();

    private static PlacesApiClient instance;
    private Retrofit retrofit;

    private PlacesApiClient() {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
        httpClient.addInterceptor(loggingInterceptor);

        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(httpClient.build())
                .build();
    }

    public static PlacesApiClient getInstance() {
        if (instance == null) {
            instance = new PlacesApiClient();
        }
        return instance;
    }

    public PlacesService getPlacesService() {
        return retrofit.create(PlacesService.class);
    }

}

相关内容

热门资讯

2分钟攻略!哈糖大菠萝攻略(透... 2分钟攻略!哈糖大菠萝攻略(透视)都是存在有辅助脚本(哔哩哔哩)小薇(辅助器软件下载)致您一封信;亲...
三分钟资料!德普之星透视辅助软... 三分钟资料!德普之星透视辅助软件(透视)一直是有辅助神器(哔哩哔哩)1、下载好德普之星透视辅助软件透...
一分钟指南!智星德州插件202... 一分钟指南!智星德州插件2024最新版(透视)好像存在有辅助脚本(哔哩哔哩)1、全新机制【智星德州插...
第1分钟攻略!约局吧如何查看是... 第1分钟攻略!约局吧如何查看是否有挂(透视)原来存在有辅助下载(哔哩哔哩)约局吧如何查看是否有挂辅助...
第七分钟学习!hhpoker辅... 第七分钟学习!hhpoker辅助软件(透视)本来真的是有辅助插件(哔哩哔哩)1、hhpoker辅助软...
四分钟总结!hhpoker免费... 四分钟总结!hhpoker免费辅助器(透视)真是真的是有辅助下载(哔哩哔哩)1.hhpoker免费辅...
第二分钟手册!wepoker辅... 第二分钟手册!wepoker辅助器(透视)其实是真的有辅助教程(哔哩哔哩)1、完成wepoker辅助...
4分钟窍要!wepoker透视... 4分钟窍要!wepoker透视功能下载(透视)果然有辅助神器(哔哩哔哩)1、全新机制【wepoker...
三分钟妙计!wepoker私人... 三分钟妙计!wepoker私人局有透视吗(透视)一直真的有辅助工具(哔哩哔哩)1、三分钟妙计!wep...
七分钟方针!拱趴大菠萝自动计算... 七分钟方针!拱趴大菠萝自动计算机器人(透视)原来存在有辅助辅助(哔哩哔哩)1、完成拱趴大菠萝自动计算...