2013-07-09 31 views
0

谷歌的API API_KEY使用一個例子,我發現了地圖API如何配置在Android

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

現在我試圖用calandar API的android:name屬性,我已經成功至今。 。我不確定我應該在這裏使用的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" 
} 

有誰知道還有什麼我需要做的正確配置呢?

call 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> 

谷歌API訪問:https://code.google.com/apis/console 1.如果你調試,需要添加一個應用程序,客戶端ID用於安裝 應用程序:證書指紋(SHA1):「keytool -list -v -keystore〜/ .android/debug.keystore輸入密碼:機器人」 2.應用程序類型:Android 3.找到API KEY:簡單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(); 
... 
+0

如何使用日曆API第3版谷歌網站的例子來驗證你在'manifest.xml'中添加了''嗎?你可以發貼嗎? – marshallino16

+0

你試圖訪問哪個日曆api? – Sharj

+0

日曆API V3 – qinmiao

回答

1

您不必提供任何東西此清單僅適用於Google Maps for Android。

如果你要使用日曆API V3(https://developers.google.com/google-apps/calendar/),那麼首先你需要使用OAuth 2

下面是關於如何在Android https://code.google.com/p/google-api-java-client/wiki/OAuth2#Android

+0

謝謝 的原因:setApplicationName( 「myAppName」),則必須你的應用程序名稱 憑證= GoogleAccountCredential.usingOAuth2(getActivity(), Collections.singleton(CalendarScopes.CALENDAR_READONLY)); SharedPreferences設置= getActivity()。getPreferences(Context.MODE_PRIVATE); credential.setSelectedAccountName(「myAccount」); client = new com.google.api.services.calendar.Calendar.Builder( transport,jsonFactory,credential).setApplicationName(「myAppName」) .build(); – qinmiao