簡體   English   中英

如何在Android上配置Google api api_key

[英]How to configure the google api api_key on Android

通過一個示例,我找到了地圖API的android:name屬性

<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="your_api_key"/>

現在,我正在嘗試使用calandar api,到目前為止,我一直都沒有成功。。我不確定我應該在這里使用的android:name值。

<meta-data
    android:name="com.google.android.calendar.v3.API_KEY"<!-- the value ?-->
    android:value="your_api_key"/>

響應:

"code": 403,
"errors": [
{
"domain": "usageLimits",
"message": "Access Not Configured",
"reason": "accessNotConfigured"
}
],
"message": "Access Not Configured"
}

有人知道我還需要做什么才能正確配置嗎?

呼叫google api:CalendarList feed = client.calendarList()。list()。setFields(CalendarInfo.FEED_FIELDS).execute();

//Traffic Reports for API Project
Total requests
2
Requests/day
2 peak 0.07 average
Start Date
Jun 12, 2013

解決它:

Manifest.xml

<application ... >

    <meta-data
        android:name="com.google.android.calendar.v3.API_KEY"
        android:value="your api key"/>
....
</application>

Google API訪問: https : //code.google.com/apis/console 1.如果需要調試,則需要添加應用程序,已安裝應用程序的客戶端ID: 證書指紋(SHA1) :“ keytool -list -v -keystore〜/ .android / debug.keystore輸入密碼:android。2.應用程序類型:Android 3.查找API密鑰: 簡單API訪問 ->瀏覽器應用程序的密鑰(帶有引薦來源)-> API密鑰:dhjkl..hjkl 4。查找產品名稱: 品牌信息 ->產品名稱

然后調用API:

final HttpTransport transport = AndroidHttp.newCompatibleTransport();

final JsonFactory jsonFactory = new GsonFactory();

GoogleAccountCredential credential;

credential =
GoogleAccountCredential.usingOAuth2(getActivity(),
        Collections.singleton(CalendarScopes.CALENDAR_READONLY));
credential.setSelectedAccountName("myAccount");
client = new com.google.api.services.calendar.Calendar.Builder(
        transport, jsonFactory, credential).setApplicationName("myAppName")
        .build();
...
checkGooglePlayStatus() 
... 
...
//doInBackground()
CalendarList feed = client.calendarList().list().setFields(CalendarInfo.FEED_FIELDS).execute();
...

您無需在清單中提供僅適用於Android Google Maps的任何內容。

如果您嘗試使用Calendar API v3( https://developers.google.com/google-apps/calendar/ ),則首先需要使用OAuth 2進行身份驗證。

這是Google網站上的示例,說明如何在Android https://code.google.com/p/google-api-java-client/wiki/OAuth2#Android上使用Calendar API v3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM