Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add dependencies in a Maven pom.xml. Add missing AuthHandler class. F…

…ix getUrl bug. Comment out writes so developers aren't annoyed.
  • Loading branch information...
commit 932f911ae2abee5e41a7d1384088ffc5ab113a82 1 parent cb79267
Yevgeniy Brikman authored
31 java/pom.xml
View
@@ -0,0 +1,31 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.linkedin.sample</groupId>
+ <artifactId>api-get-started</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.scribe</groupId>
+ <artifactId>scribe</artifactId>
+ <version>1.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ </dependencies>
+</project>
49 java/src/com/linkedin/sample/AuthHandler.java
View
@@ -0,0 +1,49 @@
+package com.linkedin.sample;
+
+import org.scribe.model.Token;
+import org.scribe.model.Verifier;
+import org.scribe.oauth.OAuthService;
+
+import java.io.Serializable;
+import java.util.Scanner;
+
+/**
+ * This will be the class to handles getting the Access Token It will take an
+ * API Key and API secret and return a @Token that is an access token It will
+ * handle the case when they Access token has already been granted
+ *
+ * User: scitronp Date: 11/11/11 Time: 3:12 PM
+ */
+public class AuthHandler implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private Token accessToken = null;
+
+ public AuthHandler(OAuthService serviceProvider)
+ {
+
+ // this is our first time creating this object so we need to populate the
+ // accessToken
+
+ Scanner in = new Scanner(System.in);
+ Token requestToken = serviceProvider.getRequestToken();
+ System.out.println(serviceProvider.getAuthorizationUrl(requestToken));
+ System.out.println("And paste the verifier here");
+ System.out.print(">>");
+ Verifier verifier = new Verifier(in.nextLine());
+
+ accessToken = serviceProvider.getAccessToken(requestToken, verifier);
+
+ }
+
+ /**
+ * You only need to call this if you didn't reserialize an object
+ *
+ * @return an Access token you can use to make API calls
+ */
+ public Token getAccessToken()
+ {
+ return this.accessToken;
+ }
+
+}
13 java/src/com/linkedin/sample/Main.java
View
@@ -32,6 +32,7 @@
import java.io.*;
import java.util.HashMap;
+import java.util.Map;
public class Main {
@@ -186,7 +187,7 @@ public static void main(String[] args) {
request.addQuerystringParameter("title", "Développeur");
request.addQuerystringParameter("facet", "industry,4");
request.addQuerystringParameter("facets", "location,industry");
- System.out.println(request.getCompleteUrl());
+ System.out.println(request.getUrl());
service.signRequest(accessToken, request);
response = request.send();
System.out.println(response.getBody());
@@ -248,7 +249,11 @@ public static void main(String[] args) {
**************************/
-
+/*
+ * Commented out so we don't write into your LinkedIn/Twitter feed while you are just testing out
+ * some code. Uncomment if you'd like to see writes in action.
+ *
+ *
System.out.println("********Write to the share - using XML********");
//This basic shares some basic information on the users activity stream
//https://developer.linkedin.com/documents/share-api
@@ -309,7 +314,7 @@ public static void main(String[] args) {
request.addHeader("Content-Type", "application/json");
request.addHeader("x-li-format", "json");
//make the json payload using json-simple
- HashMap jsonMap = new HashMap();
+ Map<String, Object> jsonMap = new HashMap<String, Object>();
jsonMap.put("comment", "Posting from the API using JSON");
JSONObject contentObject = new JSONObject();
contentObject.put("title", "This is a another test post");
@@ -326,7 +331,7 @@ public static void main(String[] args) {
System.out.println(response.getBody());
System.out.println(response.getHeaders().toString());
System.out.println();System.out.println();
-
+*/
/**************************
*
Please sign in to comment.
Something went wrong with that request. Please try again.