スマートフォン・ジン | Smartphone-Zine

引っ越し先→ https://smartphone-zine.com/

Google カレンダーAPIを理解する

GoogleカレンダーAPIを早急に理解する必要が発生しました。 GoogleカレンダーAPIとは 新規イベント作成や修正、削除、イベントの削除などの機能を持ったカレンダーアプリケーションを開発することができます。 RESTfullスタイルの呼び出しで色々な言語(currently Java, Python, PHP, .NET and Ruby)からGoogleカレンダーのデータを参照・修正することができます。 (RESTfullとはパラメータ指定でHTTPアクセスするとXMLで記述されたメッセージが送られてくるようなインタフェースの事です。)

公式ページは https://developers.google.com/google-apps/calendar/?hl=ja だそうです。英語ですね。 現在はVerson3です。Version1,2のサポートは徐々に打ち切られるようですね。 APIドキュメントは以下 https://developers.google.com/apis-explorer/#s/calendar/v3/ うーんよくわかりません。 ということで、まずはプロジェクトを登録 Google カレンダーAPIを使う前にクライアントをGoogle APIs コンソールで登録しないといけないみたいです。コンソールでプロジェクト(設定とAPIアクセス情報の名前の集まり)を作成します。 登録するにはhttps://code.google.com/apis/console で、Google Calendar APIをONにします。 ONにすると、利用規約に同意しなければなりません。利用規約は次のようになっています。 Google APIs Terms of Service Last modified: December 9, 2011 Thank you for using Google's APIs. These APIs are provided by Google Inc. (referred to as Google, we, our, or us in these terms), located at 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States. These terms outline your rights and responsibilities when using our APIs, so read them carefully. Additional terms may apply to the use of an API, including additional terms of service, terms within the accompanying API documentation, and any applicable policies or guidelines. If there is a conflict between these terms and the additional terms, the additional terms apply for that conflict. If you use the APIs as an interface to, or in conjunction with other Google products and services, then the terms for such products and services also apply. Account and Registration Accepting the Terms You may not use the APIs and may not accept the Terms if (a) you are not of legal age to form a binding contract with Google, or (b) you are a person barred from using or receiving the APIs under the applicable laws of the United States or other countries including the country in which you are resident or from which you use the APIs. Your Google Account You may need to create a Google account in order to use an API or a Google account may be assigned to you by an administrator, such as your employer or educational institution. If you are using a Google account assigned to you by an administrator, your legal relationship with your administrator may affect that account. It's your responsibility to keep your password, account credentials, and accounts secure. If you learn of any unauthorized use of your account, follow the instructions at http://www.google.com/support/accounts/bin/answer.py?answer=58585. Registration In order to access certain APIs you may be required to provide certain information (such as identification or contact details) as part of the registration process for the APIs, or as part of your continued use of the APIs. You agree that any registration information you give to Google will always be accurate and up to date. Subsidiaries and Affiliates Google has subsidiaries and affiliated legal entities around the world. You agree that these companies may provide the APIs to you on behalf of Google and these terms will also govern your relationship with these companies. Using Our APIs Your End Users You will require your end users to comply with any applicable law and these terms. You will not knowingly enable your end users to violate applicable law or these terms. Compliance with Law You will use our APIs only as permitted by law (including without limitation laws regarding the import or export of data or software, privacy, or local laws). You will not use the APIs to encourage or promote illegal activity. Permitted Access You will only access (or attempt to access) an API by the means described in the documentation of that API. If Google assigns you developer credentials or Client IDs, you must use them with the applicable APIs. You will not misrepresent or mask either your identity or your API Client's identity when using the APIs or developer accounts. API Limitations Google may set limits on the number of API requests that you can make, at its sole discretion. You agree to such limitations and will not attempt to circumvent such limitations. Open Source Software Some of the software required by or included in our APIs may be offered under an open source license. There may be provisions in the open source license that expressly override some of these terms, and in those cases, the overriding provisions apply. Monitoring Google may monitor the use of the APIs to ensure quality, improve Google products and services, and verify your compliance with these terms. You will not interfere with such monitoring. Google may use any technical means to overcome such interference. Communication with Google You agree that we may send you certain communications in connection with your use of the APIs. Please review the applicable API documentation for information about opting out of certain types of communication. Feedback If you provide feedback or suggestions about our APIs, then we may use such information without obligation to you. Your API Clients API Clients The APIs are designed to help you enhance your websites and applications (API Client(s)). Google reserves the right to investigate any API Client for compliance with these terms. Such investigations may include Google accessing and using your API Client, for example to identify security issues that could affect Google or its users. You consent to any such investigation. Google may suspend access to our APIs by you or your API Client without notice if we reasonably believe that you are in violation of these terms. Security You will use commercially reasonable efforts to protect user information collected by your API Client, including personally identifiable information (PII), from unauthorized access or use and will promptly report to your users any unauthorized access or use of such information. Ownership Google does not acquire ownership in your API Clients, and by using our APIs, you do not acquire ownership of any rights in our APIs or the content that is accessed through our APIs. User Privacy and API Clients You will comply with all privacy laws and regulations including those applying to PII. You will provide and adhere to a privacy policy for your API Client that clearly and accurately describes to users of your API Client what user information you collect (such as PII, login information and Google account data) and how you use and share such information (including for advertising) with Google and third parties. If your privacy policy is used to comply with the EU Data Protection Directive, then it must adhere to the US Safe Harbor principles of Notice, Choice, Onward Transfer, Security, Data Integrity, and Access at http://www.export.gov/safeharbor/eu/eg_main_018475.asp. Prohibitions API Prohibitions When using the APIs, the following prohibitions apply: You will not sublicense an API for use by a third party. Consequently, you will not create an API Client that functions substantially the same as the APIs and offer it for use by third parties. You will not perform an action with the intent of introducing to Google products and services any viruses, worms, defects, Trojan horses, malware or any items of a destructive nature. You will not defame, abuse, harass, stalk or threaten others. You will not interfere with or disrupt the APIs or the servers or networks providing the APIs. You will not promote or facilitate unlawful online gambling or disruptive commercial messages or advertisements. You will not reverse engineer or attempt to extract the source code from any API or any related software, except to the extent that this restriction is expressly prohibited by applicable law. Certain developer credentials are, by their nature, considered confidential. You will not disclose such confidential credentials to any third party except your agent(s) using such information solely on your behalf in accordance with these terms and under a written duty of confidentiality. Our communications to you may contain Google confidential information. If you receive any materials or communications that are clearly confidential or marked confidential, then you will not disclose the Google confidential information to any third party without Google's prior written consent. Content Content Accessible Through our APIs Our APIs contain some third party content (such as text, images, videos, audio, or software). This content is the sole responsibility of the person that makes it available. We may sometimes review content to determine whether it is illegal or violates our policies, and we may remove or refuse to display content. Finally, content accessible through our APIs may be subject to intellectual property rights, and, if so, you may not use it unless you are licensed to do so by the owner of that content or are otherwise permitted by law. Your access to the content provided by the API may be restricted, limited, or filtered in accordance with local laws, regulations, and policies. Advertising Google reserves the right in its discretion to include advertising in the content returned through the APIs. If any advertisements are returned, you may not modify such advertisements and you must show them in accordance with the relevant API documentation. Submission of Content Some of our APIs allow the submission of content, and except as expressly provided in these terms, Google does not acquire any ownership of any intellectual property rights that you or your end users hold in the content that you submit to our APIs through your API Client. By submitting, posting or displaying content to or from the APIs through your API Client, you give Google a perpetual, irrevocable, worldwide, royalty-free, and non-exclusive license to reproduce, adapt, modify, translate, publish, publicly perform, publicly display and distribute such content. However, Google will only use such content for the purpose of enabling Google to provide the APIs and only in accordance with the applicable Google privacy policies. You agree that this license includes a right for Google to make such content available to other companies, organizations or individuals with whom Google has relationships for the provision of syndicated services, and to use such content in connection with the provision of those services. Before you submit content to our APIs through your API Client, ensure that you have the necessary rights (including the necessary rights from your end users) to grant us the license. Retrieval of content When a user's non-public content is obtained through the APIs, you may not expose that content to other users or to third parties without explicit opt-in consent from that user. Data Portability Google supports data portability. By accessing users' data through the APIs for use in any of your services or applications, you agree to enable your users of any such service or application to export their equivalent data to other services or applications of their choice in a way that's substantially as fast and easy as exporting such data from Google products and services, subject to applicable laws. Prohibitions on Content Unless expressly permitted by the content owner or by applicable law, you agree that you will not, and will not permit your end users to, do the following with content returned from the APIs: Scrape, build databases or otherwise create permanent copies of such content, or keep cached copies longer than permitted by the cache header; Copy, translate, modify, create a derivative work of, sell, lease, lend, convey, distribute, publicly display or sublicense to any third party; Misrepresent the source or ownership; or Remove, obscure, or alter any copyright, trademark or other proprietary rights notices, falsify or delete any author attributions, legal notices or other labels of the origin or source of material. Brand Features; Attribution Brand Features "Brand Features" is defined as the trade names, trademarks, service marks, logos, domain names, and other distinctive brand features of each party. Except where expressly stated, these terms do not grant either party any right, title, or interest in or to the other party's Brand Features. All use by you of Google's Brand Features (including any goodwill associated therewith) will inure to the benefit of Google. Attribution You agree to display any attribution(s) required by Google as described in the documentation for the API. Google hereby grants to you a nontransferable, nonsublicenseable, nonexclusive license during the term to display Google's Brand Features for the purpose of promoting or advertising that you use the APIs. You must only use the Google Brand Features in accordance with these terms and for the purpose of fulfilling your obligations under this Section. In using Google's Brand Features, you must follow the Google Brand Features Use Guidelines at http://www.google.com/permissions/guidelines.html. You understand and agree that Google has the sole discretion to determine whether your attribution(s) and use of Google's Brand Features are in accordance with the above requirements and guidelines. Publicity You will not make any statement regarding your use of an API which suggests partnership with, sponsorship by or endorsement by Google without Google's prior written approval. Promotional and Marketing Use In the course of promoting, marketing, or demonstrating the APIs you are using and the associated Google products, Google may produce and distribute incidental depictions, including screenshots, video, or other content from your API Client, and may use your company or product name. You grant us all necessary rights for the above purposes. Privacy and Copyright Protection Google Privacy Policies By using our APIs, you agree that Google can use submitted information in accordance with our privacy policies, such as http://www.google.com/privacypolicy.html. Google DMCA Policy We provide information to help copyright holders manage their intellectual property online, but we can't determine whether something is being used legally or not without their input. We respond to notices of alleged copyright infringement and terminate accounts of repeat infringers according to the process set out in the U.S. Digital Millennium Copyright Act. If you think somebody is violating your copyrights and want to notify us, you can find information about submitting notices, and Google's policy about responding to notices at http://www.google.com/dmca.html. Termination Termination You may stop using our APIs at any time. If you want to terminate these terms, you must provide Google with 7 days prior written notice and upon termination, cease your use of the applicable APIs. Google reserves the right to terminate these terms or discontinue the APIs or any portion or feature for any reason and at any time without liability or other obligation to you. Your Obligations Post-Termination Upon any termination of these terms or discontinuation of your access to an API, you will immediately stop using the API, cease all use of the Google Brand Features, and delete any cached or stored content that was permitted by the cache header under Section 5. Google may independently communicate with any account owner whose account(s) are associated with your API Client and developer credentials to provide notice of the termination of your right to use an API. Surviving Provisions When these terms come to an end, those terms that by their nature are intended to continue indefinitely will continue to apply, including but not limited to: Sections 8, 9, and 10. Liability for our APIs WARRANTIES NEITHER GOOGLE NOR ITS SUPPLIERS OR DISTRIBUTORS MAKE ANY SPECIFIC PROMISES ABOUT THE APIS. FOR EXAMPLE, WE DON'T MAKE ANY COMMITMENTS ABOUT THE QUALITY OF THE APIS OR THE CONTENT ACCESSED THROUGH THE APIS, THEIR RELIABILITY, AVAILABILITY OR ABILITY TO MEET YOUR NEEDS. THE APIS AND CONTENT ACCESSED THROUGH THE APIS ARE PROVIDED "AS IS". SOME JURISDICTIONS PROVIDE FOR CERTAIN WARRANTIES, LIKE THE IMPLIED WARRANTY OF THE MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. TO THE EXTENT PERMITTED BY LAW, WE EXCLUDE ALL IMPLIED WARRANTIES. LIMITATION OF LIABILITY WHEN PERMITTED BY LAW, GOOGLE, AND GOOGLE'S SUPPLIERS AND DISTRIBUTORS, WILL NOT BE RESPONSIBLE FOR LOST PROFITS, REVENUES, OR DATA, FINANCIAL LOSSES OR INDIRECT, SPECIAL, CONSEQUENTIAL, EXEMPLARY, OR PUNITIVE DAMAGES. TO THE EXTENT PERMITTED BY LAW, THE TOTAL LIABILITY OF GOOGLE, AND ITS SUPPLIERS AND DISTRIBUTORS, FOR ANY CLAIM UNDER THESE TERMS, INCLUDING FOR ANY WARRANTIES THAT MAY NOT LEGALLY BE EXCLUDED, IS LIMITED TO THE AMOUNT YOU PAID US TO USE THE APIS (OR, IF WE CHOOSE, TO SUPPLYING YOU THE APIS AGAIN) DURING THE SIX MONTHS PRIOR TO THE EVENT GIVING RISE TO THE LIABILITY. NOTHING IN THESE TERMS LIMITS YOUR RESPONSIBILITY FOR INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. IN ALL CASES, GOOGLE, AND ITS SUPPLIERS AND DISTRIBUTORS, WILL NOT BE LIABLE FOR ANY LOSS OR DAMAGE THAT IS NOT REASONABLY FORESEEABLE. Indemnification You agree to hold harmless and indemnify Google, and its subsidiaries, affiliates, officers, agents, and employees, or partners, from and against any third party claim arising from or in any way related to: your misuse or your end user's misuse of the APIs; or your violation or your end user's violation of these terms, including any liability or expense arising from all claims, losses, damages (actual and consequential), suits, judgments, litigation costs and attorneys' fees, of every kind and nature. In such a case, Google will provide you with written notice of such claim, suit or action. General Provisions Modification We may modify these terms or any additional terms that apply to an API occasionally, for example, to reflect changes to the law or changes to our APIs. We'll post notice of modifications to these terms or the additional terms within the documentation of each applicable API. Changes are effective seven (7) days after they are posted. However, changes specific to new functionality for an API or changes made for legal reasons will be effective immediately. You agree that your continued use of the API constitutes an acceptance of the modified terms. General Legal Terms These terms control the relationship between Google and you. They do not create any third party beneficiary rights. If you do not comply with these terms, and Google does not take action right away, this does not mean that Google is giving up any rights that it may have (such as taking action in the future). If it turns out that a particular term is not enforceable, this will not affect any other terms. The laws of California, U.S.A., excluding California's choice of law rules, will apply to any disputes arising out of or related to these terms or the services. ALL CLAIMS ARISING OUT OF OR RELATING TO THESE TERMS OR THE SERVICES WILL BE LITIGATED EXCLUSIVELY IN THE FEDERAL OR STATE COURTS OF SANTA CLARA COUNTY, CALIFORNIA, USA, AND YOU AND GOOGLE CONSENT TO PERSONAL JURISDICTION IN THOSE COURTS. Google Calendar APIs Terms of Service Last modified: April 20, 2012 By using this API, you consent to be bound by these terms in addition to the Google APIs Terms of Service ("API ToS") at http://code.google.com/apis/terms/index.html. Data location You acknowledge that any information provided by users through the Calendar APIs will be handled and stored by Google and that such information may be stored and processed in the United States or any other country in which Google or its subsidiaries or affiliated legal entities maintain facilities. By using the Calendar APIs, you consent and will obtain any necessary consent from your users to any such transfer of information. Deprecation Policy Google will announce if we intend to discontinue or make backwards incompatible changes to this API or Service. We will use commercially reasonable efforts to continue to operate Versions 1 and 2 of the Calendar Data API without these changes until November 17, 2014, unless (as Google determines in its reasonable good faith judgment): required by law or third party relationship (including if there is a change in applicable law or relationship), or doing so could create a security risk or substantial economic or material technical burden. This Deprecation Policy doesn't apply to versions, features, and functionality labeled as "experimental." After November 17, 2014, this Deprecation Policy will not apply. 利用規約に同意したら、今度はGoogleAPIコンソールの「API Access」を開きます。「Simple API Access」という項目のなかにAPIキーが表示されています。 ちなみに、 Google Calendarのアクセスは1日に1万アクセスと決まっています。これを増やすには、GoogleAPIのコンソールのQuotasから、「Request more...」のリンクをクリックして「Calendar API quota request」にアプリケーションの説明を記載して送信しないといけないようです。 APIを呼び出すには2種類の方法があります。 ・HTTPリクエストを送信して応答をパースする。(RESTfull) ・クライアントライブラリを使う。https://developers.google.com/google-apps/calendar/downloads クライアントライブラリは以下の種類が用意されています。 Google APIs Client Library for .NET (beta) Google APIs Client Library for Go (alpha) Google API Libraries for Google Web Toolkit (alpha) Google APIs Client Library for Java (beta) Google APIs Client Library for JavaScript (beta) Google APIs Client Library for Objective C (alpha) Google APIs Client Library for PHP (beta) Google APIs Client Library for Python (beta) Google APIs Client Library for Ruby (alpha) うーん、どれもα版やβ版です。大丈夫なのでしょうか。とはいえクライアントライブラリを使ったほうが楽そうですね。 というわけでライブラリとサンプルをダウンロードしてみましょう。 [bash] svn checkout http://google-api-objectivec-client.googlecode.com/svn/trunk/ google-api-objectivec-client-read-only [/bash] ダウンロードした [text] google-api-objectivec-client-read-only/Examples/CalendarSample/CalendarSample.xcodeproj [/text] を開きます。 さてビルドして実行しましょう。 すると [text] error: /Users/kaneda/Documents/iOS/google-api-objectivec-client-read-only/Source/JSON/SBJsonBase.h: No such file or directory [/text] といったエラーが出ます。どうもJSONフォルダがまるごとと存在しないみたい。自分で追加する必要がありそうです。 SBJsonのサイトhttp://stig.github.com/json-framework/ から、 https://github.com/downloads/stig/json-framework/JSON%20v2.3.2%20(iOS).zip をダウンロードします。展開した中にClassesというフォルがあるので Source/JSONというフォルダを作成してそこにClassesの中身を全てコピーします。 これで再度ビルドして実行してみましょう。今度はうまく実行出来ました。