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);
    }

}

相关内容

热门资讯

普及透视!pokemmo手机辅... 普及透视!pokemmo手机辅助软件!一贯一直总是有辅助工具(有挂透视)-哔哩哔哩1、打开软件启动之...
详情透视!约局吧透视挂下载!切... 详情透视!约局吧透视挂下载!切实是有辅助教程(有挂分享)-哔哩哔哩1、金币登录送、破产送、升级送、活...
详情透视!约局吧是否有挂!其实... 详情透视!约局吧是否有挂!其实一直总是有辅助插件(有挂规律)-哔哩哔哩1、点击下载安装,约局吧是否有...
必备透视!佛手大菠萝有挂吗!切... 必备透视!佛手大菠萝有挂吗!切实是真的有辅助技巧(有挂方针)-哔哩哔哩1、每一步都需要思考,不同水平...
解迷透视!werplan外卦神... 解迷透视!werplan外卦神器!竟然是有辅助软件(确实有挂)-哔哩哔哩小薇(辅助器软件下载)致您一...
揭幕透视!poker worl... 揭幕透视!poker world辅助!切实有辅助攻略(真实有挂)-哔哩哔哩1、每一步都需要思考,不同...
普及透视!拱趴大菠萝作必弊方法... 普及透视!拱趴大菠萝作必弊方法!竟然一直总是有辅助脚本(有挂总结)-哔哩哔哩1)拱趴大菠萝作必弊方法...
了解透视!fishpoker透... 了解透视!fishpoker透视!本来一直都是有辅助技巧(有挂方法)-哔哩哔哩1、fishpoker...
推荐透视!pokemmo辅助官... 推荐透视!pokemmo辅助官网!确实是真的有辅助方法(有挂透视)-哔哩哔哩1、任何pokemmo辅...
开挂透视!德州圈脚本!一贯是有... 开挂透视!德州圈脚本!一贯是有辅助技巧(讲解有挂)-哔哩哔哩德州圈脚本破解侠是真的助透视。每个模型中...