After watching an interesting youtube video of the API by jenny murphy, I explored the API interactively using the google plus api developers site.
Clicking on REST API, you can go to each api resource (people, activities, comments, oauth) and explore the API including running an example request and seeing the results. I have a google plus identity (+Ed) so I posted a couple of public messages to play with.
I was able to download the google plus java client api and google plus java starter project.
I followed these steps to get started
Copy the google java starter project web app example (./google-plus-java-starter/web-app) to a new directory to begin playing. The instructions are in the readme.txt to get started.
In order to access the API, you first have to register your application using the google api console and get a token for oauth and access to the specific api. The steps
- go to https://code.google.com/apis/console/b/0/?api=plus
- click on 'create project'
- agree to the terms of service (and read :)) (two of them)
- Select the google+API (if not already selected (note the url I supplied should select this)
- CLick on API access (left side menu)
- Click on Create an OAuth 2.0 client ID
- describe your project (and upload logo if you have it) and press next
- select application type=web app, and site host name to run locally, select http: and enter localhost
- click 'create client ID'
- there are 4 pieces of info that you'll need to copy to your project: client id, client secret, redirect URI and API key (from the Simple API access)
in your new project (copied from starter) open src/main/resources/config.properties
paste in the 4 bits of information from the registration process (the redirect URI may already be correct)
now from the project root, use maven to launch the project using the built in jetty:
mvn compile jetty:run
go to your browser (chrome naturally) to check out
http://localhost:8080/
This may fail (the version I had downloaded _v5 did fail)
If you get an exception thrown when first accessing with error:
Exception initializing page context java.lang.VerifyError: (class: org/apache/jasper/runtime/PageContextImpl, method: getELResolver signature: ()Ljavax/el/ELResolver;) Incompatible argument to function
Then you may need to fix the pom.xml. Open pom.xml and add scope provided element for the jsp 2.1 dependency:
<dependency> <groupid>org.mortbay.jetty</groupid> <artifactid>jsp-2.1</artifactid> <version>6.1.14</version> <scope>provided</scope> </dependency>
Then restart and access again. Then it works!
You should see 'connect me' button.
This will require you to authorize access to your account from this program. Once authorized, it presents your profile information and a list of public activities.
Now you can play with the API
No comments:
Post a Comment