├── .gitignore ├── CONTRIBUTING.md ├── README.md ├── client_secrets.json.example ├── index.html ├── lib ├── commons-logging-1.1.1-sources.jar ├── commons-logging-1.1.1.jar ├── google-api-client-1.17.0-rc.jar ├── google-api-client-1.17.0-rc.jar.properties ├── google-api-client-android-1.17.0-rc.jar ├── google-api-client-android-1.17.0-rc.jar.properties ├── google-api-client-appengine-1.17.0-rc.jar ├── google-api-client-gson-1.17.0-rc.jar ├── google-api-client-gson-1.17.0-rc.jar.properties ├── google-api-client-jackson2-1.17.0-rc.jar ├── google-api-client-jackson2-1.17.0-rc.jar.properties ├── google-api-client-java6-1.17.0-rc.jar ├── google-api-client-protobuf-1.17.0-rc.jar ├── google-api-client-protobuf-1.17.0-rc.jar.properties ├── google-api-client-servlet-1.17.0-rc.jar ├── google-api-client-xml-1.17.0-rc.jar ├── google-api-client-xml-1.17.0-rc.jar.properties ├── google-api-services-plus-v1-rev104-1.17.0-rc-javadoc.jar ├── google-api-services-plus-v1-rev104-1.17.0-rc-sources.jar ├── google-api-services-plus-v1-rev104-1.17.0-rc.jar ├── google-http-client-1.17.0-rc.jar ├── google-http-client-1.17.0-rc.jar.properties ├── google-http-client-android-1.17.0-rc.jar ├── google-http-client-android-1.17.0-rc.jar.properties ├── google-http-client-appengine-1.17.0-rc.jar ├── google-http-client-gson-1.17.0-rc.jar ├── google-http-client-gson-1.17.0-rc.jar.properties ├── google-http-client-jackson-1.17.0-rc.jar ├── google-http-client-jackson-1.17.0-rc.jar.properties ├── google-http-client-jackson2-1.17.0-rc.jar ├── google-http-client-jackson2-1.17.0-rc.jar.properties ├── google-http-client-jdo-1.17.0-rc.jar ├── google-http-client-protobuf-1.17.0-rc.jar ├── google-http-client-protobuf-1.17.0-rc.jar.properties ├── google-http-client-xml-1.17.0-rc.jar ├── google-http-client-xml-1.17.0-rc.jar.properties ├── google-oauth-client-1.17.0-rc.jar ├── google-oauth-client-1.17.0-rc.jar.properties ├── google-oauth-client-appengine-1.17.0-rc.jar ├── google-oauth-client-java6-1.17.0-rc.jar ├── google-oauth-client-jetty-1.17.0-rc.jar ├── google-oauth-client-servlet-1.17.0-rc.jar ├── gson-2.1-sources.jar ├── gson-2.1.jar ├── gson-2.1.jar.properties ├── guava-jdk5-13.0-sources.jar ├── guava-jdk5-13.0.jar ├── httpclient-4.0.1-sources.jar ├── httpclient-4.0.1.jar ├── httpcore-4.0.1-sources.jar ├── httpcore-4.0.1.jar ├── jackson-core-2.0.5-sources.jar ├── jackson-core-2.0.5.jar ├── jackson-core-2.1.3.jar ├── jackson-core-2.1.3.jar.properties ├── jackson-core-asl-1.9.11.jar ├── jackson-core-asl-1.9.11.jar.properties ├── jackson-core-asl-1.9.9-sources.jar ├── jackson-core-asl-1.9.9.jar ├── jdo2-api-2.3-eb-sources.jar ├── jdo2-api-2.3-eb.jar ├── jetty-6.1.26-sources.jar ├── jetty-6.1.26.jar ├── jetty-util-6.1.26-sources.jar ├── jetty-util-6.1.26.jar ├── jetty-webapp-7.3.0.v20110203.jar ├── jsr305-1.3.9.jar ├── log4j-1.2.14.jar ├── protobuf-java-2.4.1-sources.jar ├── protobuf-java-2.4.1.jar ├── protobuf-java-2.4.1.jar.properties ├── servlet-api-3.0.pre4.jar ├── slf4j-api-1.6.1.jar ├── slf4j-log4j12-1.6.1.jar ├── transaction-api-1.1-sources.jar ├── transaction-api-1.1.jar ├── xpp3-1.1.4c-sources.jar └── xpp3-1.1.4c.jar ├── mvn ├── .gitignore ├── README.md ├── client_secrets.json.example ├── index.html ├── pom.xml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── google │ │ └── plus │ │ └── samples │ │ └── quickstart │ │ └── Signin.java └── static │ └── signin_button.png ├── src └── com │ └── google │ └── plus │ └── samples │ └── quickstart │ └── Signin.java └── static └── signin_button.png /.gitignore: -------------------------------------------------------------------------------- 1 | /client_secrets.json 2 | /bin/ 3 | /.project 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement 9 | (CLA). 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then you'll need to sign an [individual CLA] 13 | (http://code.google.com/legal/individual-cla-v1.0.html). 14 | * If you work for a company that wants to allow you to contribute your work, 15 | then you'll need to sign a [corporate CLA] 16 | (http://code.google.com/legal/corporate-cla-v1.0.html). 17 | 18 | Follow either of the two links above to access the appropriate CLA and 19 | instructions for how to sign and return it. Once we receive it, we'll be able to 20 | accept your pull requests. 21 | 22 | ## Contributing A Patch 23 | 24 | 1. Sign a Contributor License Agreement, if you have not yet done so (see 25 | details above). 26 | 1. Create your change to the repo in question. 27 | * Fork the desired repo, develop and test your code changes. 28 | * Ensure that your code is clear and comprehensible. 29 | * Ensure that your code has an appropriate set of unit tests which all pass. 30 | 1. Submit a pull request. 31 | 1. The repo owner will review your request. If it is approved, the change will 32 | be merged. If it needs additional work, the repo owner will respond with 33 | useful comments. 34 | 35 | ## Contributing A New Sample App 36 | 37 | 1. Sign a Contributor License Agreement, if you have not yet done so (see 38 | details above). 39 | 1. Create your own repo for your app following this naming convention: 40 | * gplus-{app-name}-{language} 41 | * apps: quickstart, photohunt-server, photohunt-client 42 | * example: gplus-quickstart-android 43 | * For multi-language apps, concatenate the primary languages like this: 44 | gplus-photohunt-server-java-python. 45 | 46 | 1. Create your sample app in this repo. 47 | * Be sure to clone the README.md, CONTRIBUTING.md and LICENSE files from the 48 | googleplus repo. 49 | * Ensure that your code is clear and comprehensible. 50 | * Ensure that your code has an appropriate set of unit tests which all pass. 51 | * Instructional value is the top priority when evaluating new app proposals for 52 | this collection of repos. 53 | 1. Submit a request to fork your repo in googleplus organization. 54 | 1. The repo owner will review your request. If it is approved, the sample will 55 | be merged. If it needs additional work, the repo owner will respond with 56 | useful comments. 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google+ Java Quickstart 2 | 3 | The instructions are now here: 4 | https://developers.google.com/+/quickstart/java 5 | -------------------------------------------------------------------------------- /client_secrets.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "web": { 3 | "client_id": "YOUR_CLIENT_ID", 4 | "client_secret": "YOUR_CLIENT_SECRET", 5 | "redirect_uris": ["postmessage"], 6 | "auth_uri": "https://accounts.google.com/o/oauth2/auth", 7 | "token_uri": "https://accounts.google.com/o/oauth2/token" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | {{ APPLICATION_NAME }} 25 | 36 | 38 | 39 | 40 | 50 | 51 |
52 | Sign in with Google+ 54 |
55 | 76 | 77 | 290 | 291 | -------------------------------------------------------------------------------- /lib/commons-logging-1.1.1-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/commons-logging-1.1.1-sources.jar -------------------------------------------------------------------------------- /lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /lib/google-api-client-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-api-client-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-api-client-android-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-android-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-android-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-api-client-android-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-api-client-appengine-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-appengine-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-gson-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-gson-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-gson-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-api-client-gson-${project.api.version}-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-api-client-jackson2-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-jackson2-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-jackson2-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-api-client-jackson2-${project.api.version}-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-api-client-java6-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-java6-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-protobuf-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-protobuf-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-protobuf-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-api-client-protobuf-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-api-client-servlet-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-servlet-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-xml-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-client-xml-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-api-client-xml-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-api-client-xml-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-api-services-plus-v1-rev104-1.17.0-rc-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-services-plus-v1-rev104-1.17.0-rc-javadoc.jar -------------------------------------------------------------------------------- /lib/google-api-services-plus-v1-rev104-1.17.0-rc-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-services-plus-v1-rev104-1.17.0-rc-sources.jar -------------------------------------------------------------------------------- /lib/google-api-services-plus-v1-rev104-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-api-services-plus-v1-rev104-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-http-client-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-http-client-android-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-android-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-android-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-http-client-android-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-http-client-appengine-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-appengine-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-gson-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-gson-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-gson-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-http-client-gson-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-http-client-jackson-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-jackson-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-jackson-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-http-client-jackson-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-http-client-jackson2-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-jackson2-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-jackson2-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-http-client-jackson2-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-http-client-jdo-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-jdo-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-protobuf-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-protobuf-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-protobuf-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-http-client-protobuf-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-http-client-xml-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-http-client-xml-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-http-client-xml-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-http-client-xml-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-oauth-client-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-oauth-client-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-oauth-client-1.17.0-rc.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/google-oauth-client-1.17.0-rc-sources.jar 2 | -------------------------------------------------------------------------------- /lib/google-oauth-client-appengine-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-oauth-client-appengine-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-oauth-client-java6-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-oauth-client-java6-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-oauth-client-jetty-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-oauth-client-jetty-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/google-oauth-client-servlet-1.17.0-rc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/google-oauth-client-servlet-1.17.0-rc.jar -------------------------------------------------------------------------------- /lib/gson-2.1-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/gson-2.1-sources.jar -------------------------------------------------------------------------------- /lib/gson-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/gson-2.1.jar -------------------------------------------------------------------------------- /lib/gson-2.1.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/gson-2.1-sources.jar 2 | -------------------------------------------------------------------------------- /lib/guava-jdk5-13.0-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/guava-jdk5-13.0-sources.jar -------------------------------------------------------------------------------- /lib/guava-jdk5-13.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/guava-jdk5-13.0.jar -------------------------------------------------------------------------------- /lib/httpclient-4.0.1-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/httpclient-4.0.1-sources.jar -------------------------------------------------------------------------------- /lib/httpclient-4.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/httpclient-4.0.1.jar -------------------------------------------------------------------------------- /lib/httpcore-4.0.1-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/httpcore-4.0.1-sources.jar -------------------------------------------------------------------------------- /lib/httpcore-4.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/httpcore-4.0.1.jar -------------------------------------------------------------------------------- /lib/jackson-core-2.0.5-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jackson-core-2.0.5-sources.jar -------------------------------------------------------------------------------- /lib/jackson-core-2.0.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jackson-core-2.0.5.jar -------------------------------------------------------------------------------- /lib/jackson-core-2.1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jackson-core-2.1.3.jar -------------------------------------------------------------------------------- /lib/jackson-core-2.1.3.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/jackson-core-2.1.3-sources.jar 2 | -------------------------------------------------------------------------------- /lib/jackson-core-asl-1.9.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jackson-core-asl-1.9.11.jar -------------------------------------------------------------------------------- /lib/jackson-core-asl-1.9.11.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/jackson-core-asl-1.9.11-sources.jar 2 | -------------------------------------------------------------------------------- /lib/jackson-core-asl-1.9.9-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jackson-core-asl-1.9.9-sources.jar -------------------------------------------------------------------------------- /lib/jackson-core-asl-1.9.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jackson-core-asl-1.9.9.jar -------------------------------------------------------------------------------- /lib/jdo2-api-2.3-eb-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jdo2-api-2.3-eb-sources.jar -------------------------------------------------------------------------------- /lib/jdo2-api-2.3-eb.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jdo2-api-2.3-eb.jar -------------------------------------------------------------------------------- /lib/jetty-6.1.26-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jetty-6.1.26-sources.jar -------------------------------------------------------------------------------- /lib/jetty-6.1.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jetty-6.1.26.jar -------------------------------------------------------------------------------- /lib/jetty-util-6.1.26-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jetty-util-6.1.26-sources.jar -------------------------------------------------------------------------------- /lib/jetty-util-6.1.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jetty-util-6.1.26.jar -------------------------------------------------------------------------------- /lib/jetty-webapp-7.3.0.v20110203.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jetty-webapp-7.3.0.v20110203.jar -------------------------------------------------------------------------------- /lib/jsr305-1.3.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/jsr305-1.3.9.jar -------------------------------------------------------------------------------- /lib/log4j-1.2.14.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/log4j-1.2.14.jar -------------------------------------------------------------------------------- /lib/protobuf-java-2.4.1-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/protobuf-java-2.4.1-sources.jar -------------------------------------------------------------------------------- /lib/protobuf-java-2.4.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/protobuf-java-2.4.1.jar -------------------------------------------------------------------------------- /lib/protobuf-java-2.4.1.jar.properties: -------------------------------------------------------------------------------- 1 | src=../libs-sources/protobuf-java-2.4.1-sources.jar 2 | -------------------------------------------------------------------------------- /lib/servlet-api-3.0.pre4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/servlet-api-3.0.pre4.jar -------------------------------------------------------------------------------- /lib/slf4j-api-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/slf4j-api-1.6.1.jar -------------------------------------------------------------------------------- /lib/slf4j-log4j12-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/slf4j-log4j12-1.6.1.jar -------------------------------------------------------------------------------- /lib/transaction-api-1.1-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/transaction-api-1.1-sources.jar -------------------------------------------------------------------------------- /lib/transaction-api-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/transaction-api-1.1.jar -------------------------------------------------------------------------------- /lib/xpp3-1.1.4c-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/xpp3-1.1.4c-sources.jar -------------------------------------------------------------------------------- /lib/xpp3-1.1.4c.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/lib/xpp3-1.1.4c.jar -------------------------------------------------------------------------------- /mvn/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /client_secrets.json 3 | -------------------------------------------------------------------------------- /mvn/README.md: -------------------------------------------------------------------------------- 1 | # Google+ Java Quickstart with maven 2 | 3 | Prepare 4 | ------- 5 | Copy/paste client_secrets.json.example to client_secrets.json and put your credentials 6 | 7 | Build 8 | ----- 9 | ``` 10 | mvn clean install 11 | ``` 12 | 13 | Run 14 | --- 15 | ``` 16 | mvn exec:java -Dexec.mainClass="com.google.plus.samples.quickstart.Signin" 17 | ``` 18 | .. then browse [http://localhost:4567](http://localhost:4567) -------------------------------------------------------------------------------- /mvn/client_secrets.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "web": { 3 | "client_id": "YOUR_CLIENT_ID", 4 | "client_secret": "YOUR_CLIENT_SECRET", 5 | "redirect_uris": ["postmessage"], 6 | "auth_uri": "https://accounts.google.com/o/oauth2/auth", 7 | "token_uri": "https://accounts.google.com/o/oauth2/token" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /mvn/index.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | {{ APPLICATION_NAME }} 25 | 36 | 38 | 39 | 40 | 50 | 51 |
52 | Sign in with Google+ 54 |
55 | 76 | 77 | 290 | 291 | -------------------------------------------------------------------------------- /mvn/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.google 5 | gplus-quickstart-java 6 | 0.0.1-SNAPSHOT 7 | 8 | 9 | 10 | 11 | maven-compiler-plugin 12 | 2.3.2 13 | 14 | 1.7 15 | 1.7 16 | 17 | 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 24 | 25 | 26 | 27 | com.google.oauth-client 28 | google-oauth-client 29 | 1.20.0 30 | 31 | 32 | com.google.api-client 33 | google-api-client 34 | 1.20.0 35 | 36 | 37 | com.google.http-client 38 | google-http-client 39 | 1.20.0 40 | 41 | 42 | javax.servlet 43 | servlet-api 44 | 2.5 45 | 46 | 47 | com.google.code.gson 48 | gson 49 | 2.3.1 50 | 51 | 52 | org.mortbay.jetty 53 | jetty 54 | 6.1.26 55 | 56 | 57 | com.google.http-client 58 | google-http-client-jackson 59 | 1.20.0 60 | 61 | 62 | com.google.apis 63 | google-api-services-plus 64 | v1-rev217-1.20.0 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /mvn/src/main/java/com/google/plus/samples/quickstart/Signin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.plus.samples.quickstart; 18 | 19 | import com.google.api.client.auth.oauth2.TokenResponseException; 20 | import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest; 21 | import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; 22 | import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; 23 | import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; 24 | import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse; 25 | import com.google.api.client.http.GenericUrl; 26 | import com.google.api.client.http.HttpResponse; 27 | import com.google.api.client.http.HttpTransport; 28 | import com.google.api.client.http.javanet.NetHttpTransport; 29 | import com.google.api.client.json.jackson.JacksonFactory; 30 | import com.google.api.services.plus.Plus; 31 | import com.google.api.services.plus.model.PeopleFeed; 32 | import com.google.gson.Gson; 33 | 34 | import org.mortbay.jetty.Server; 35 | import org.mortbay.jetty.servlet.ServletHandler; 36 | import org.mortbay.jetty.servlet.SessionHandler; 37 | 38 | import org.apache.log4j.BasicConfigurator; 39 | 40 | import java.io.BufferedReader; 41 | import java.io.ByteArrayOutputStream; 42 | import java.io.File; 43 | import java.io.FileInputStream; 44 | import java.io.FileNotFoundException; 45 | import java.io.FileReader; 46 | import java.io.IOException; 47 | import java.io.InputStream; 48 | import java.io.InputStreamReader; 49 | import java.io.Reader; 50 | import java.math.BigInteger; 51 | import java.security.SecureRandom; 52 | import java.util.Scanner; 53 | 54 | import javax.servlet.ServletException; 55 | import javax.servlet.http.HttpServlet; 56 | import javax.servlet.http.HttpServletRequest; 57 | import javax.servlet.http.HttpServletResponse; 58 | 59 | /** 60 | * Simple server to demonstrate how to use Google+ Sign-In and make a request 61 | * via your own server. 62 | * 63 | * @author joannasmith@google.com (Joanna Smith) 64 | * @author vicfryzel@google.com (Vic Fryzel) 65 | */ 66 | public class Signin { 67 | /* 68 | * Default HTTP transport to use to make HTTP requests. 69 | */ 70 | private static final HttpTransport TRANSPORT = new NetHttpTransport(); 71 | 72 | /* 73 | * Default JSON factory to use to deserialize JSON. 74 | */ 75 | private static final JacksonFactory JSON_FACTORY = new JacksonFactory(); 76 | 77 | /* 78 | * Gson object to serialize JSON responses to requests to this servlet. 79 | */ 80 | private static final Gson GSON = new Gson(); 81 | 82 | /* 83 | * Creates a client secrets object from the client_secrets.json file. 84 | */ 85 | private static GoogleClientSecrets clientSecrets; 86 | 87 | static { 88 | try { 89 | Reader reader = new FileReader("client_secrets.json"); 90 | clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, reader); 91 | } catch (IOException e) { 92 | throw new Error("No client_secrets.json found", e); 93 | } 94 | } 95 | 96 | /* 97 | * This is the Client ID that you generated in the API Console. 98 | */ 99 | private static final String CLIENT_ID = clientSecrets.getWeb().getClientId(); 100 | 101 | /* 102 | * This is the Client Secret that you generated in the API Console. 103 | */ 104 | private static final String CLIENT_SECRET = clientSecrets.getWeb().getClientSecret(); 105 | 106 | /* 107 | * Optionally replace this with your application's name. 108 | */ 109 | private static final String APPLICATION_NAME = "Google+ Java Quickstart"; 110 | 111 | /** 112 | * Register all endpoints that we'll handle in our server. 113 | * @param args Command-line arguments. 114 | * @throws Exception from Jetty if the component fails to start 115 | */ 116 | public static void main(String[] args) throws Exception { 117 | BasicConfigurator.configure(); 118 | Server server = new Server(4567); 119 | ServletHandler servletHandler = new ServletHandler(); 120 | SessionHandler sessionHandler = new SessionHandler(); 121 | sessionHandler.setHandler(servletHandler); 122 | server.setHandler(sessionHandler); 123 | servletHandler.addServletWithMapping(ConnectServlet.class, "/connect"); 124 | servletHandler.addServletWithMapping(DisconnectServlet.class, "/disconnect"); 125 | servletHandler.addServletWithMapping(PeopleServlet.class, "/people"); 126 | servletHandler.addServletWithMapping(MainServlet.class, "/"); 127 | server.start(); 128 | server.join(); 129 | } 130 | 131 | /** 132 | * Initialize a session for the current user, and render index.html. 133 | */ 134 | public static class MainServlet extends HttpServlet { 135 | 136 | @Override 137 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 138 | throws ServletException, IOException { 139 | // This check serves the signin button image 140 | if ("/signin_button.png".equals(request.getServletPath())) { 141 | File staticFile = new File("./static/signin_button.png"); 142 | FileInputStream fileStream = new FileInputStream(staticFile); 143 | byte []buf = new byte[(int)staticFile.length()]; 144 | fileStream.read(buf); 145 | response.setContentType("image/png"); 146 | response.getOutputStream().write(buf); 147 | response.setStatus(HttpServletResponse.SC_OK); 148 | return; 149 | } 150 | 151 | // This check prevents the "/" handler from handling all requests by default 152 | if (!"/".equals(request.getServletPath())) { 153 | response.setStatus(HttpServletResponse.SC_NOT_FOUND); 154 | return; 155 | } 156 | 157 | response.setContentType("text/html"); 158 | try { 159 | // Create a state token to prevent request forgery. 160 | // Store it in the session for later validation. 161 | String state = new BigInteger(130, new SecureRandom()).toString(32); 162 | request.getSession().setAttribute("state", state); 163 | // Fancy way to read index.html into memory, and set the client ID 164 | // and state values in the HTML before serving it. 165 | response.getWriter().print(new Scanner(new File("index.html"), "UTF-8") 166 | .useDelimiter("\\A").next() 167 | .replaceAll("[{]{2}\\s*CLIENT_ID\\s*[}]{2}", CLIENT_ID) 168 | .replaceAll("[{]{2}\\s*STATE\\s*[}]{2}", state) 169 | .replaceAll("[{]{2}\\s*APPLICATION_NAME\\s*[}]{2}", 170 | APPLICATION_NAME) 171 | .toString()); 172 | response.setStatus(HttpServletResponse.SC_OK); 173 | } catch (FileNotFoundException e) { 174 | // When running the quickstart, there was some path issue in finding 175 | // index.html. Double check the quickstart guide. 176 | e.printStackTrace(); 177 | response.setStatus(HttpServletResponse.SC_NOT_FOUND); 178 | response.getWriter().print(e.toString()); 179 | } 180 | } 181 | } 182 | 183 | /** 184 | * Upgrade given auth code to token, and store it in the session. 185 | * POST body of request should be the authorization code. 186 | * Example URI: /connect?state=...&gplus_id=... 187 | */ 188 | public static class ConnectServlet extends HttpServlet { 189 | @Override 190 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 191 | throws ServletException, IOException { 192 | response.setContentType("application/json"); 193 | 194 | // Only connect a user that is not already connected. 195 | String tokenData = (String) request.getSession().getAttribute("token"); 196 | if (tokenData != null) { 197 | response.setStatus(HttpServletResponse.SC_OK); 198 | response.getWriter().print(GSON.toJson("Current user is already connected.")); 199 | return; 200 | } 201 | // Ensure that this is no request forgery going on, and that the user 202 | // sending us this connect request is the user that was supposed to. 203 | if (!request.getParameter("state").equals(request.getSession().getAttribute("state"))) { 204 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 205 | response.getWriter().print(GSON.toJson("Invalid state parameter.")); 206 | return; 207 | } 208 | // Normally the state would be a one-time use token, however in our 209 | // simple case, we want a user to be able to connect and disconnect 210 | // without reloading the page. Thus, for demonstration, we don't 211 | // implement this best practice. 212 | //request.getSession().removeAttribute("state"); 213 | 214 | ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); 215 | getContent(request.getInputStream(), resultStream); 216 | String code = new String(resultStream.toByteArray(), "UTF-8"); 217 | 218 | try { 219 | // Upgrade the authorization code into an access and refresh token. 220 | GoogleTokenResponse tokenResponse = 221 | new GoogleAuthorizationCodeTokenRequest(TRANSPORT, JSON_FACTORY, 222 | CLIENT_ID, CLIENT_SECRET, code, "postmessage").execute(); 223 | 224 | // You can read the Google user ID in the ID token. 225 | // This sample does not use the user ID. 226 | GoogleIdToken idToken = tokenResponse.parseIdToken(); 227 | String gplusId = idToken.getPayload().getSubject(); 228 | 229 | // Store the token in the session for later use. 230 | request.getSession().setAttribute("token", tokenResponse.toString()); 231 | response.setStatus(HttpServletResponse.SC_OK); 232 | response.getWriter().print(GSON.toJson("Successfully connected user.")); 233 | } catch (TokenResponseException e) { 234 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 235 | response.getWriter().print(GSON.toJson("Failed to upgrade the authorization code.")); 236 | } catch (IOException e) { 237 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 238 | response.getWriter().print(GSON.toJson("Failed to read token data from Google. " + 239 | e.getMessage())); 240 | } 241 | } 242 | 243 | /* 244 | * Read the content of an InputStream. 245 | * 246 | * @param inputStream the InputStream to be read. 247 | * @return the content of the InputStream as a ByteArrayOutputStream. 248 | * @throws IOException 249 | */ 250 | static void getContent(InputStream inputStream, ByteArrayOutputStream outputStream) 251 | throws IOException { 252 | // Read the response into a buffered stream 253 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 254 | int readChar; 255 | while ((readChar = reader.read()) != -1) { 256 | outputStream.write(readChar); 257 | } 258 | reader.close(); 259 | } 260 | } 261 | 262 | /** 263 | * Revoke current user's token and reset their session. 264 | */ 265 | public static class DisconnectServlet extends HttpServlet { 266 | @Override 267 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 268 | throws ServletException, IOException { 269 | response.setContentType("application/json"); 270 | 271 | // Only disconnect a connected user. 272 | String tokenData = (String) request.getSession().getAttribute("token"); 273 | if (tokenData == null) { 274 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 275 | response.getWriter().print(GSON.toJson("Current user not connected.")); 276 | return; 277 | } 278 | try { 279 | // Build credential from stored token data. 280 | GoogleCredential credential = new GoogleCredential.Builder() 281 | .setJsonFactory(JSON_FACTORY) 282 | .setTransport(TRANSPORT) 283 | .setClientSecrets(CLIENT_ID, CLIENT_SECRET).build() 284 | .setFromTokenResponse(JSON_FACTORY.fromString( 285 | tokenData, GoogleTokenResponse.class)); 286 | // Execute HTTP GET request to revoke current token. 287 | HttpResponse revokeResponse = TRANSPORT.createRequestFactory() 288 | .buildGetRequest(new GenericUrl( 289 | String.format( 290 | "https://accounts.google.com/o/oauth2/revoke?token=%s", 291 | credential.getAccessToken()))).execute(); 292 | // Reset the user's session. 293 | request.getSession().removeAttribute("token"); 294 | response.setStatus(HttpServletResponse.SC_OK); 295 | response.getWriter().print(GSON.toJson("Successfully disconnected.")); 296 | } catch (IOException e) { 297 | // For whatever reason, the given token was invalid. 298 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 299 | response.getWriter().print(GSON.toJson("Failed to revoke token for given user.")); 300 | } 301 | } 302 | } 303 | 304 | /** 305 | * Get list of people user has shared with this app. 306 | */ 307 | public static class PeopleServlet extends HttpServlet { 308 | @Override 309 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 310 | throws ServletException, IOException { 311 | response.setContentType("application/json"); 312 | 313 | // Only fetch a list of people for connected users. 314 | String tokenData = (String) request.getSession().getAttribute("token"); 315 | if (tokenData == null) { 316 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 317 | response.getWriter().print(GSON.toJson("Current user not connected.")); 318 | return; 319 | } 320 | try { 321 | // Build credential from stored token data. 322 | GoogleCredential credential = new GoogleCredential.Builder() 323 | .setJsonFactory(JSON_FACTORY) 324 | .setTransport(TRANSPORT) 325 | .setClientSecrets(CLIENT_ID, CLIENT_SECRET).build() 326 | .setFromTokenResponse(JSON_FACTORY.fromString( 327 | tokenData, GoogleTokenResponse.class)); 328 | // Create a new authorized API client. 329 | Plus service = new Plus.Builder(TRANSPORT, JSON_FACTORY, credential) 330 | .setApplicationName(APPLICATION_NAME) 331 | .build(); 332 | // Get a list of people that this user has shared with this app. 333 | PeopleFeed people = service.people().list("me", "visible").execute(); 334 | response.setStatus(HttpServletResponse.SC_OK); 335 | response.getWriter().print(GSON.toJson(people)); 336 | } catch (IOException e) { 337 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 338 | response.getWriter().print(GSON.toJson("Failed to read data from Google. " + 339 | e.getMessage())); 340 | } 341 | } 342 | } 343 | } 344 | -------------------------------------------------------------------------------- /mvn/static/signin_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/mvn/static/signin_button.png -------------------------------------------------------------------------------- /src/com/google/plus/samples/quickstart/Signin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.plus.samples.quickstart; 18 | 19 | import com.google.api.client.auth.oauth2.TokenResponseException; 20 | import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest; 21 | import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; 22 | import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; 23 | import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; 24 | import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse; 25 | import com.google.api.client.http.GenericUrl; 26 | import com.google.api.client.http.HttpResponse; 27 | import com.google.api.client.http.HttpTransport; 28 | import com.google.api.client.http.javanet.NetHttpTransport; 29 | import com.google.api.client.json.jackson.JacksonFactory; 30 | import com.google.api.services.plus.Plus; 31 | import com.google.api.services.plus.model.PeopleFeed; 32 | import com.google.gson.Gson; 33 | 34 | import org.mortbay.jetty.Server; 35 | import org.mortbay.jetty.servlet.ServletHandler; 36 | import org.mortbay.jetty.servlet.SessionHandler; 37 | 38 | import org.apache.log4j.BasicConfigurator; 39 | 40 | import java.io.BufferedReader; 41 | import java.io.ByteArrayOutputStream; 42 | import java.io.File; 43 | import java.io.FileInputStream; 44 | import java.io.FileNotFoundException; 45 | import java.io.FileReader; 46 | import java.io.IOException; 47 | import java.io.InputStream; 48 | import java.io.InputStreamReader; 49 | import java.io.Reader; 50 | import java.math.BigInteger; 51 | import java.security.SecureRandom; 52 | import java.util.Scanner; 53 | 54 | import javax.servlet.ServletException; 55 | import javax.servlet.http.HttpServlet; 56 | import javax.servlet.http.HttpServletRequest; 57 | import javax.servlet.http.HttpServletResponse; 58 | 59 | /** 60 | * Simple server to demonstrate how to use Google+ Sign-In and make a request 61 | * via your own server. 62 | * 63 | * @author joannasmith@google.com (Joanna Smith) 64 | * @author vicfryzel@google.com (Vic Fryzel) 65 | */ 66 | public class Signin { 67 | /* 68 | * Default HTTP transport to use to make HTTP requests. 69 | */ 70 | private static final HttpTransport TRANSPORT = new NetHttpTransport(); 71 | 72 | /* 73 | * Default JSON factory to use to deserialize JSON. 74 | */ 75 | private static final JacksonFactory JSON_FACTORY = new JacksonFactory(); 76 | 77 | /* 78 | * Gson object to serialize JSON responses to requests to this servlet. 79 | */ 80 | private static final Gson GSON = new Gson(); 81 | 82 | /* 83 | * Creates a client secrets object from the client_secrets.json file. 84 | */ 85 | private static GoogleClientSecrets clientSecrets; 86 | 87 | static { 88 | try { 89 | Reader reader = new FileReader("client_secrets.json"); 90 | clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, reader); 91 | } catch (IOException e) { 92 | throw new Error("No client_secrets.json found", e); 93 | } 94 | } 95 | 96 | /* 97 | * This is the Client ID that you generated in the API Console. 98 | */ 99 | private static final String CLIENT_ID = clientSecrets.getWeb().getClientId(); 100 | 101 | /* 102 | * This is the Client Secret that you generated in the API Console. 103 | */ 104 | private static final String CLIENT_SECRET = clientSecrets.getWeb().getClientSecret(); 105 | 106 | /* 107 | * Optionally replace this with your application's name. 108 | */ 109 | private static final String APPLICATION_NAME = "Google+ Java Quickstart"; 110 | 111 | /** 112 | * Register all endpoints that we'll handle in our server. 113 | * @param args Command-line arguments. 114 | * @throws Exception from Jetty if the component fails to start 115 | */ 116 | public static void main(String[] args) throws Exception { 117 | BasicConfigurator.configure(); 118 | Server server = new Server(4567); 119 | ServletHandler servletHandler = new ServletHandler(); 120 | SessionHandler sessionHandler = new SessionHandler(); 121 | sessionHandler.setHandler(servletHandler); 122 | server.setHandler(sessionHandler); 123 | servletHandler.addServletWithMapping(ConnectServlet.class, "/connect"); 124 | servletHandler.addServletWithMapping(DisconnectServlet.class, "/disconnect"); 125 | servletHandler.addServletWithMapping(PeopleServlet.class, "/people"); 126 | servletHandler.addServletWithMapping(MainServlet.class, "/"); 127 | server.start(); 128 | server.join(); 129 | } 130 | 131 | /** 132 | * Initialize a session for the current user, and render index.html. 133 | */ 134 | public static class MainServlet extends HttpServlet { 135 | 136 | @Override 137 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 138 | throws ServletException, IOException { 139 | // This check serves the signin button image 140 | if ("/signin_button.png".equals(request.getServletPath())) { 141 | File staticFile = new File("./static/signin_button.png"); 142 | FileInputStream fileStream = new FileInputStream(staticFile); 143 | byte []buf = new byte[(int)staticFile.length()]; 144 | fileStream.read(buf); 145 | response.setContentType("image/png"); 146 | response.getOutputStream().write(buf); 147 | response.setStatus(HttpServletResponse.SC_OK); 148 | return; 149 | } 150 | 151 | // This check prevents the "/" handler from handling all requests by default 152 | if (!"/".equals(request.getServletPath())) { 153 | response.setStatus(HttpServletResponse.SC_NOT_FOUND); 154 | return; 155 | } 156 | 157 | response.setContentType("text/html"); 158 | try { 159 | // Create a state token to prevent request forgery. 160 | // Store it in the session for later validation. 161 | String state = new BigInteger(130, new SecureRandom()).toString(32); 162 | request.getSession().setAttribute("state", state); 163 | // Fancy way to read index.html into memory, and set the client ID 164 | // and state values in the HTML before serving it. 165 | response.getWriter().print(new Scanner(new File("index.html"), "UTF-8") 166 | .useDelimiter("\\A").next() 167 | .replaceAll("[{]{2}\\s*CLIENT_ID\\s*[}]{2}", CLIENT_ID) 168 | .replaceAll("[{]{2}\\s*STATE\\s*[}]{2}", state) 169 | .replaceAll("[{]{2}\\s*APPLICATION_NAME\\s*[}]{2}", 170 | APPLICATION_NAME) 171 | .toString()); 172 | response.setStatus(HttpServletResponse.SC_OK); 173 | } catch (FileNotFoundException e) { 174 | // When running the quickstart, there was some path issue in finding 175 | // index.html. Double check the quickstart guide. 176 | e.printStackTrace(); 177 | response.setStatus(HttpServletResponse.SC_NOT_FOUND); 178 | response.getWriter().print(e.toString()); 179 | } 180 | } 181 | } 182 | 183 | /** 184 | * Upgrade given auth code to token, and store it in the session. 185 | * POST body of request should be the authorization code. 186 | * Example URI: /connect?state=...&gplus_id=... 187 | */ 188 | public static class ConnectServlet extends HttpServlet { 189 | @Override 190 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 191 | throws ServletException, IOException { 192 | response.setContentType("application/json"); 193 | 194 | // Only connect a user that is not already connected. 195 | String tokenData = (String) request.getSession().getAttribute("token"); 196 | if (tokenData != null) { 197 | response.setStatus(HttpServletResponse.SC_OK); 198 | response.getWriter().print(GSON.toJson("Current user is already connected.")); 199 | return; 200 | } 201 | // Ensure that this is no request forgery going on, and that the user 202 | // sending us this connect request is the user that was supposed to. 203 | if (!request.getParameter("state").equals(request.getSession().getAttribute("state"))) { 204 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 205 | response.getWriter().print(GSON.toJson("Invalid state parameter.")); 206 | return; 207 | } 208 | // Normally the state would be a one-time use token, however in our 209 | // simple case, we want a user to be able to connect and disconnect 210 | // without reloading the page. Thus, for demonstration, we don't 211 | // implement this best practice. 212 | //request.getSession().removeAttribute("state"); 213 | 214 | ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); 215 | getContent(request.getInputStream(), resultStream); 216 | String code = new String(resultStream.toByteArray(), "UTF-8"); 217 | 218 | try { 219 | // Upgrade the authorization code into an access and refresh token. 220 | GoogleTokenResponse tokenResponse = 221 | new GoogleAuthorizationCodeTokenRequest(TRANSPORT, JSON_FACTORY, 222 | CLIENT_ID, CLIENT_SECRET, code, "postmessage").execute(); 223 | 224 | // You can read the Google user ID in the ID token. 225 | // This sample does not use the user ID. 226 | GoogleIdToken idToken = tokenResponse.parseIdToken(); 227 | String gplusId = idToken.getPayload().getSubject(); 228 | 229 | // Store the token in the session for later use. 230 | request.getSession().setAttribute("token", tokenResponse.toString()); 231 | response.setStatus(HttpServletResponse.SC_OK); 232 | response.getWriter().print(GSON.toJson("Successfully connected user.")); 233 | } catch (TokenResponseException e) { 234 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 235 | response.getWriter().print(GSON.toJson("Failed to upgrade the authorization code.")); 236 | } catch (IOException e) { 237 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 238 | response.getWriter().print(GSON.toJson("Failed to read token data from Google. " + 239 | e.getMessage())); 240 | } 241 | } 242 | 243 | /* 244 | * Read the content of an InputStream. 245 | * 246 | * @param inputStream the InputStream to be read. 247 | * @return the content of the InputStream as a ByteArrayOutputStream. 248 | * @throws IOException 249 | */ 250 | static void getContent(InputStream inputStream, ByteArrayOutputStream outputStream) 251 | throws IOException { 252 | // Read the response into a buffered stream 253 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 254 | int readChar; 255 | while ((readChar = reader.read()) != -1) { 256 | outputStream.write(readChar); 257 | } 258 | reader.close(); 259 | } 260 | } 261 | 262 | /** 263 | * Revoke current user's token and reset their session. 264 | */ 265 | public static class DisconnectServlet extends HttpServlet { 266 | @Override 267 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 268 | throws ServletException, IOException { 269 | response.setContentType("application/json"); 270 | 271 | // Only disconnect a connected user. 272 | String tokenData = (String) request.getSession().getAttribute("token"); 273 | if (tokenData == null) { 274 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 275 | response.getWriter().print(GSON.toJson("Current user not connected.")); 276 | return; 277 | } 278 | try { 279 | // Build credential from stored token data. 280 | GoogleCredential credential = new GoogleCredential.Builder() 281 | .setJsonFactory(JSON_FACTORY) 282 | .setTransport(TRANSPORT) 283 | .setClientSecrets(CLIENT_ID, CLIENT_SECRET).build() 284 | .setFromTokenResponse(JSON_FACTORY.fromString( 285 | tokenData, GoogleTokenResponse.class)); 286 | // Execute HTTP GET request to revoke current token. 287 | HttpResponse revokeResponse = TRANSPORT.createRequestFactory() 288 | .buildGetRequest(new GenericUrl( 289 | String.format( 290 | "https://accounts.google.com/o/oauth2/revoke?token=%s", 291 | credential.getAccessToken()))).execute(); 292 | // Reset the user's session. 293 | request.getSession().removeAttribute("token"); 294 | response.setStatus(HttpServletResponse.SC_OK); 295 | response.getWriter().print(GSON.toJson("Successfully disconnected.")); 296 | } catch (IOException e) { 297 | // For whatever reason, the given token was invalid. 298 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 299 | response.getWriter().print(GSON.toJson("Failed to revoke token for given user.")); 300 | } 301 | } 302 | } 303 | 304 | /** 305 | * Get list of people user has shared with this app. 306 | */ 307 | public static class PeopleServlet extends HttpServlet { 308 | @Override 309 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 310 | throws ServletException, IOException { 311 | response.setContentType("application/json"); 312 | 313 | // Only fetch a list of people for connected users. 314 | String tokenData = (String) request.getSession().getAttribute("token"); 315 | if (tokenData == null) { 316 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 317 | response.getWriter().print(GSON.toJson("Current user not connected.")); 318 | return; 319 | } 320 | try { 321 | // Build credential from stored token data. 322 | GoogleCredential credential = new GoogleCredential.Builder() 323 | .setJsonFactory(JSON_FACTORY) 324 | .setTransport(TRANSPORT) 325 | .setClientSecrets(CLIENT_ID, CLIENT_SECRET).build() 326 | .setFromTokenResponse(JSON_FACTORY.fromString( 327 | tokenData, GoogleTokenResponse.class)); 328 | // Create a new authorized API client. 329 | Plus service = new Plus.Builder(TRANSPORT, JSON_FACTORY, credential) 330 | .setApplicationName(APPLICATION_NAME) 331 | .build(); 332 | // Get a list of people that this user has shared with this app. 333 | PeopleFeed people = service.people().list("me", "visible").execute(); 334 | response.setStatus(HttpServletResponse.SC_OK); 335 | response.getWriter().print(GSON.toJson(people)); 336 | } catch (IOException e) { 337 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 338 | response.getWriter().print(GSON.toJson("Failed to read data from Google. " + 339 | e.getMessage())); 340 | } 341 | } 342 | } 343 | } 344 | -------------------------------------------------------------------------------- /static/signin_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/gplus-quickstart-java/91e9ed0ef9130a9b8f1dc35544edea09516bf850/static/signin_button.png --------------------------------------------------------------------------------