Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Stas Gromov edited this pageMar 22, 2019 ·5 revisions

How to work with other APIs

You probably will have to work with an API that's not supported out of the box by ScribeJava. This is almost as easy, you'll just gonna need to create a simple class.

Creating your Api class

Let's suppose you want to work with a 1.0a provider called Jimbo, it's api has the following endpoints:

request token: http://jimbo.com/oauth/request_tokenaccess token: http://jimbo.com/oauth/access_tokenauthorize: http://jimbo.com/oauth/authorize_jimbo?token=<your token here>

ScribeJava does not support it out of the box so naturally, you panic. Don't. The only thing you need to do is make your JimboApi.class like this:

publicclassJimboApiextendsDefaultApi10a {privatestaticfinalStringAUTHORIZE_URL ="http://jimbo.com/oauth/authorize?token=%s";protectedJimboApi() {    }privatestaticclassInstanceHolder {privatestaticfinalJimboApiINSTANCE =newJimboApi();    }publicstaticJimboApiinstance() {returnInstanceHolder.INSTANCE;    }@OverridepublicStringgetAccessTokenEndpoint(){return"http://jimbo.com/oauth/access_token";    }@OverridepublicStringgetRequestTokenEndpoint() {return"http://jimbo.com/oauth/request_token";    }@OverridepublicStringgetAuthorizationUrl(OAuth1RequestTokenrequestToken) {returnString.format(AUTHORIZE_URL,requestToken.getToken());    }}

The default signature type for ScribeJava uses the request's header. If your API uses query string parameters for the signature, be sure to override getSignatureType method:

@OverridepublicOAuth1SignatureTypegetSignatureType() {returnOAuth1SignatureType.QueryString;    }

Create the Jimbo service

finalOAuth10aServiceservice =newServiceBuilder("6icbcAXyZx67r8uTAUM5Qw")//apiKey here                                .apiSecret("SCCAdUUc6LXxiazxH3N0QfpNUvlUy84mZ2XZKiv39s")                                .build(JimboApi.instance());

That's it!

Well you got it! easy right?

P.S. Remember, it's a wiki, it's always less or more outdated. Working executable (checked on the compile time) examples arehere

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp