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

Add Api for Airtable#1062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
abhikvarma wants to merge2 commits intoscribejava:master
base:master
Choose a base branch
Loading
fromabhikvarma:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,6 +55,7 @@ ScribeJava support out-of-box several HTTP clients:

### Supports all (50+) major 1.0a and 2.0 OAuth APIs out-of-the-box

* Airtable (https://airtable.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AirtableExample.java)
* Asana (https://asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java)
* Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java)
* AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
package com.github.scribejava.apis;

import com.github.scribejava.core.builder.api.DefaultApi20;

/**
* Airtable.com API
*/
public class AirtableApi extends DefaultApi20 {

protected AirtableApi() {
}

private static class InstanceHolder {
private static final AirtableApi INSTANCE = new AirtableApi();
}

public static AirtableApi instance() {
return InstanceHolder.INSTANCE;
}

@Override
public String getAccessTokenEndpoint() {
return "https://airtable.com/oauth2/v1/token";
}

@Override
public String getAuthorizationBaseUrl() {
return "https://airtable.com/oauth2/v1/authorize";
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
package com.github.scribejava.apis.examples;

import java.io.IOException;
import java.security.SecureRandom;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;

import com.github.scribejava.apis.AirtableApi;
import com.github.scribejava.core.base64.Base64;
import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.model.OAuth2AccessToken;
import com.github.scribejava.core.model.OAuthRequest;
import com.github.scribejava.core.model.Response;
import com.github.scribejava.core.model.Verb;
import com.github.scribejava.core.oauth.AccessTokenRequestParams;
import com.github.scribejava.core.oauth.AuthorizationUrlBuilder;
import com.github.scribejava.core.oauth.OAuth20Service;

public class AirtableExample {

private static final String NETWORK_NAME = "Airtable";
private static final String PROTECTED_RESOURCE_URL = "https://api.airtable.com/v0/meta/whoami";

private AirtableExample() {
}

@SuppressWarnings("MPD.SystemPrintln")
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
//Replace these with your client id and secret
final String clientId = "your client id";
final String clientSecret = "your client secret";
final OAuth20Service service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.callback("https://www.example.com/oauth_callback/")
.build(AirtableApi.instance());
final Scanner in = new Scanner(System.in, "UTF-8");

System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();

// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
// Set a cryptographically generated string as the state
// https://airtable.com/developers/web/api/oauth-reference#authorization-request-query
SecureRandom random = new SecureRandom();
final byte randomBytes[] = new byte[100];
random.nextBytes(randomBytes);
// at least one scope must be requested
final String customScope = "data.records:read schema.bases:read";
final AuthorizationUrlBuilder authorizationUrlBuilder = service.createAuthorizationUrlBuilder()
.scope(customScope)
.state(Base64.encodeUrlWithoutPadding(randomBytes))
.initPKCE();

System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJFava here:");
System.out.println(authorizationUrlBuilder.build());
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String code = in.nextLine();
System.out.println();

System.out.println("Trading the Authorization Code for an Access Token...");
final OAuth2AccessToken accessToken = service.getAccessToken(AccessTokenRequestParams.create(code)
.pkceCodeVerifier(authorizationUrlBuilder.getPkce().getCodeVerifier()));
System.out.println("Got the Access Token!");
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();

System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);

service.signRequest(accessToken, request);

try (Response response = service.execute(request)) {
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
}

System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");

}
}

[8]ページ先頭

©2009-2025 Movatter.jp