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

}

相关内容

热门资讯

关于透视!xpoker辅助神器... 关于透视!xpoker辅助神器,微信微乐小程序有窍门吗,攻略教程(有挂详情)-哔哩哔哩进入游戏-大厅...
解迷透视!菠萝辅助器免费版的特... 解迷透视!菠萝辅助器免费版的特点,微乐自建房怎么挂脚本,练习教程(有挂分享)-哔哩哔哩运菠萝辅助器免...
解迷透视!pokemmo脚本辅... 您好,pokemmo脚本辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054...
解迷透视!hhpoker作弊实... 解迷透视!hhpoker作弊实战视频,微乐a3纸牌有脚本,手段教程(有挂方法)-哔哩哔哩hhpoke...
教你透视!sohoo竞技联盟辅... 教你透视!sohoo竞技联盟辅助器,微乐贵阳麻将辅助,法门教程(有挂规律)-哔哩哔哩所有人都在同一条...
辅助透视!wepoker怎么看... 辅助透视!wepoker怎么看牌型,微乐家乡官方app,学习教程(确实有挂)-哔哩哔哩1、下载好we...
解密透视!hhpoker可以开... 解密透视!hhpoker可以开挂吗,微乐小程序微乐房间怎么开挂,要领教程(有挂总结)-哔哩哔哩1、操...
教你透视!wpk刷入池率脚本,... 教你透视!wpk刷入池率脚本,微信小程序微乐辅助器免费版v2.0,策略教程(有挂方法)-哔哩哔哩在进...
总结透视!pokemmo脚本最... 总结透视!pokemmo脚本最新版,微乐三带辅助,绝活教程(有挂详情)-哔哩哔哩1、全新机制【pok...
解迷透视!we poker插件... 解迷透视!we poker插件,微乐游戏小程序脚本,积累教程(有挂方略)-哔哩哔哩1、上手简单,内置...