How To Use Google APIs with iPhone SDK
Adding Google API support to your iPhone App could not be any easier. Google provides Objective-C APIs for:
- Google Base
- Analytics – (Only available via SVN Trunk or manual download)
- Blogger
- Book Search
- Calendar
- Code Search
- Contacts
- Documents List
- Finance
- Health
- Picasa Web Albums
- Spreadsheets
- Webmaster Tools
- YouTube
Step 1
The first step, is to head on over to the Google Code website for the Objective-C Client, download and extract the zip file source code. Alternatively, you can get the latest and greatest version via Subversion using:
svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/ gdata-objectivec-client-read-only
If you downloaded the zip file from the website, you’ll have version 1.7.0, and if you used the svn code you’ll have a -read-only folder.
Step 2
Open up the GData XCode Project from your downloaded folder as well as your iPhone App XCode project.

Step 3
Drag over the GData Sources Folder from the GData project to your iPhone App project and add it as reference [don't check the box for Copy items into destination group's folder (if needed).] You do not need to copy over all the files into your project. You can, but it’s not required.


This will add a ton of files to your project. You may delete the APIs you are not planning on using, but make sure that the files GDataXMLNode.m and GDataXMLNode.h in the Common/Optional/XMLSupport group are not removed from your project as they are required for iPhone builds.

Step 4
Open up the build settings for your iPhone App project. Located and set the following settings.
- Header Search Paths: /usr/include/libxml2
- Other Linker Flags: -lxml2
For the Debug build configuration only, add the Other C Flags setting so that the library’s debug-only code is included:
- Other C Flags: -DDEBUG=1

Step 5 (Optional for iPhone 3.0 Beta SDK)
If you downloaded the zip file version (1.7.0) of the API, you will also run into this error message when you attempt to first build your iPhone App project:
...Source/Networking/GDataHTTPFetcherLogging.m:224: error: 'NSTask' undeclared (first use in
...Source/Networking/GDataHTTPFetcherLogging.m:224: error: 'task' undeclared (first use in this
function)

Apple has removed the NSTask from the Foundations Framework in the iPhone 3.0 SDK. In order to fix this, simply open up the GDataDefines.h file, find the developer section and add:
#define GDATA_SKIP_LOG_XMLFORMAT 1

Note: This fix is only needed if you downloaded version 1.7.0 of the GData Objective-C API and are using iPhone 3.0 Beta SDK. If you downloaded the latest Subversion read-only trunk of the code or are using iPhone 2.2.1 SDK, you do not need to do this.
Step 6
At this point, your iPhone XCode project should build successfully and you can begin using the Google APIs by simply importing the appropriate header files. ie.
#import "GDataAnalytics.h"
Step 7 (Optional if downloaded GData version 1.7.0 Zip file)
If you downloaded the zip file version (1.7.0) of the API, you will be missing the Analytics API. That has not yet been zipped up for the download. You may want to download those separately.
Additional Resources:
- Official Google Mac Blog: Using Google APIs in an iPhone App
- gdata-objectivec-client – Google Code
- Issue 24 – gdata-objectivec-client – Build failure due to removal of NSTask from IPhone SDK 3.0 – Google Code
Related Posts
Subscribe by
Follow me on
[...] Check out my previous post on How to add the Google APIs to your iPhone App project. [...]
where Do I change the build settings? I'm lost on Step 4
Open up the Inspector for your App or Target and chose the Build Settings tab. If that's not enough explanation, Apple has some more here:
http://developer.apple.com/Tools/xcode/xcodebui...
http://developer.apple.com/tools/xcode/xcodepro...
Otherwise, If that's too over the top, I can post up a few more screenshots and explanations on how to get to that section. Just let me know if you need me to do that.
Wonderful Info John. I am wondering which is the best iphone template to use for developing iphone app with Google API. Thanks a lot.
For using the Google APIs it doesn't really matter which one you pick. If you're doing the Tab Bar functionality, that's a good one to chose. If you're going to do everything in code, I'd chose Window or View Based. Otherwise, Tab Bar and Navigation are just as good. They all work well with the Google APIs.
Three20 on the other hand, I'd go with Window Based or View Based for sure.
Thanks John. The other thing i am confused a bit is do i need to drag “GData Source” folder or “GData Project” file. According to the article posted on the google code website( http://code.google.com/p/gdata-objectivec-clien...) ” To build with the static library, drag the GData project file itself into an iPhone project to make a cross-project reference, and add the GDataTouchStaticLib target as a dependency for building the app. ” It is very confusing to me, i am trying to figure out how to create a static library and dependencies. Do i really need to do this.
I am also getting some errors regarding XML file eg. tree.h not found.
Any help is appreciated.
Thanks
You can drag the Project file itself in the new version (1.8) of the GData code. At the time of writing, I believe I was using version 1.7 of the code. It has since been updated. I'll be updating the post accordingly.
Yes, you do need to do all of this. Otherwise, you won't be able to fully access all the data. It sounds like you missed an #import statement somewhere. If it's not too confidential, you may want to either post what you're trying to link to, or try contacting Greg at the GData Objective-C Google Group [ http://groups.google.com/group/gdata-objectivec... ]. He may be able to help you further.
Thanks John, I will try it again.
Thank you for this post. My compile ran error free first run.
The only difference is that for step 4, I used “$SDKROOT/usr/include/libxml2″
Thank you for this post. My compile ran error free first run (Xcode 3.1.4/IPhone SDK 3.1.2)
The only differences:
For step 4, I used “$SDKROOT/usr/include/libxml2″
I used SVN to get the latest sources and then manually placed them into a GoogleAPI folder matching the “Groups” that are in your GData project. Then I added my GoogleAPI folder to the project.
[...] basic setup for Xcode | iPhone coding is shown in this link Category: Goggle Apps You can follow any responses to this entry through the RSS 2.0 feed. [...]
[...] the iPhone SDK February 8, 2010 — Matthew Fincher Step by step instructions… How To Use Google APIs with the iPhone SDK Posted in 1. Leave a Comment [...]
Please update step 6.
With the static library linked into your project, refer directly to the headers by omitting the framework name, like
#import “GDataCalendar.h”
NOT
#import “GData/GDataCalendar.h”
I got some errors:
! “_kSecReutnData”, referenced from:
_kSecReturnData$non_lazy_ptr in GDataOAuthViewControllerTouch.o
! “_SecItemAdd”, referenced from:
…
Can you help me out? If you want to know more about the error message, please email me. Thanks
Hey John, I have been trying to connect to GData ObjC client lib and would like to use their Calendar and Health service. I integrated with Health successfully, working fine. Now, when i want to connect to calendar in the same project im getting some error with GDataServiceGoogleCalendar, it says
.objc_class_nameGDataServiceGoogleCalendar referenced from: Literal-pointer@_OBJC@_cls_refs@GDataServiceGoogleCalendar in GoogleCalendarViewController.
Symbol(s) not found Collect2:id returned 1 exit status
I don't know what is missing???? Any help is appreciated.
Thanks
Jisoo, did you find the answer. I am also facing the same issue.
Thanks
Can I use this API to do basic web searches?
I'm getting some errors when I try to build a project with GDataXMLNode. It's probably something easy, but I'm somewhat new to iPhone development. Here's the error on iPhone SDK 3.1.3:
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: file: -lxml2 is not an object file (not allowed in a library)
I had the same problem. Looking at the sample app from Google (OAuthSampleTouch), I noticed it had Security.framework and SystemConfiguration.framework. Adding these allowed me to compile.
Caveat: I haven't done anything with this code yet so it might not be a fix, I just verified that it compiles.
I'm getting the same linker errors as jisoo above using version 1.10 along with SDK 4.0 (and 3.2). Any ideas?
Hello Disqus,
I'm so sorry for not replying immediately. I couldn't make it successful.
Jisoo
Thank you, the first tutorial that has pictures and shows what to select and to move where. And is understandable.
ok! thank you for this tutorial
its build successfully with me but this is appear :
http://www.freeimagehosting.net/uploads/7f969ba...
I push to the “calendarview ” from the cell in my “rootviewcontroller” .
wait for your help,
[...] I just found this site which has some of the same steps above plus more: http://www.johntwang.com/blog/2009/06/08/how-to-use-google-apis-with-iphone-sdk/ (including debugging [...]
i got the same
can anybody help?