README.md 2.78 KB

JAVA-ORCID-CLIENT

Usage Examples

Requirements

You should import:

// Import the client
import org.um.dsi.gavea.orcid.client.OrcidOAuthClient;
import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;

// Import activities
import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
import org.um.dsi.gavea.orcid.model.activities.Identifier;
import org.um.dsi.gavea.orcid.model.activities.WorkGroup;

// Import Works
import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
import org.um.dsi.gavea.orcid.model.work.ExternalIdentifierType;
import org.um.dsi.gavea.orcid.model.work.Work;
import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
import org.um.dsi.gavea.orcid.model.work.WorkTitle;
import org.um.dsi.gavea.orcid.model.work.WorkType;

// Import Enum types
import org.um.dsi.gavea.orcid.model.common.RelationshipType;
import org.um.dsi.gavea.orcid.model.common.ScopePathType;

Generate an Access Token, using the sandbox

String loginUri = "https://sandbox.orcid.org";
String clientSecret = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
String clientId = "XXXX-XXXX-XXXX-XXXX";
String apiUri = "https://api.sandbox.orcid.org";
//Use google OAUTH playground, this should be the landing page used to receive the Authorization Code
String redirectUri = "https://developers.google.com/oauthplayground";

// This scopes will allow you to do almost anything to the user profile 
// You should limit the scopes you want to use
List<ScopePathType> scopes = new ArrayList<ScopePathType>();
scopes.add(ScopePathType.AUTHENTICATE);
scopes.add(ScopePathType.ORCID_PROFILE_READ_LIMITED);
scopes.add(ScopePathType.ACTIVITIES_UPDATE);
scopes.add(ScopePathType.ORCID_BIO_UPDATE);

// Instantiate the Orcid Client
OrcidOAuthClient orcidClient = new OrcidOAuthClient(loginUri, apiUri, clientId, clientSecret, redirectUri); 

try {
        String authorizationURI = orcidClient.getAuthorizeUriLogin(scopes,state,orcid);
        System.out.println(authorizationURI);
} catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
}

Then you should have a landing page in your project, configured in redirectUri to get the Authentication Code This method will

OrcidAccessToken orcidToken;

try {
        orcidToken = orcidClient.getAccessTokens(authorizationCode);
        accessToken = orcidToken.getAccess_token(); 
        System.out.println(accessToken);

} catch (OrcidClientException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
}

Get activities

Get a Work

Update a Work

Create a new Work

#License See LICENSE.md