Skip to content

SDK which allows one to make requests to nextdoor more comfortably via Java

License

Notifications You must be signed in to change notification settings

Kukushaa/nextdoor-java-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java SDK for nextdoor

Sonatype Logo License

Introduction

This SDK was written to make API calls for nextdoor API easier and more convenient via Java.

For nextdoor API official documentation, visit their website.

Installation

Recommended installation of SDK is via maven (or gradle etc.). The last version of dependency that needs to be injected:

<!--https://github.com/Kukushaa/nextdoor-java-sdk-->
<dependency>
    <groupId>io.github.kukushaa</groupId>
    <artifactId>nextdoor-java-sdk</artifactId>
    <version>1.1.1</version>
</dependency>

Examples

Create/Get access token

To create/get the first access token via our SDK, use the generated code below:

import com.nextdoor.exception.APIRequestException;
import com.nextdoor.models.AccessToken;

public class GenerateAccessToken {
    public static void main(String[] args) {
        final String userName = "USERNAME";
        final String password = "PASSWORD";
        final String authorizationCode = "AUTHORIZATION_CODE";
        final String clientId = "CLIENT_ID";
        final String redirectUri = "REDIRECT_URI";

        try {
            AccessToken accessToken = new NextDoorAPIAccessToken(userName, password)
                    .generate()
                    .setGrantType(AccessToken.GrantType.AUTHORIZATION_CODE)
                    .setCode(authorizationCode)
                    .setClientId(clientId)
                    .setRedirectUri(redirectUri)
                    .execute();

            System.out.println("Generated access token: " + accessToken.getAccessToken());
        } catch (APIRequestException e) {
            throw new RuntimeException(e);
        }
    }
}

After executing the code successfully, it will return AccessToken object, which includes accessToken object, which we can get via method getAccessToken() (be careful, don't share your access token!).

documentation

Create post

After creating/getting an access token, we can create the first post via our SDK.

To make that possible, use the generated code below:

public class CreatePost {
    public static void main(String[] args) {
        final String token = "TOKEN";

        try {
            Post post = new NextDoorAPIPosts(new NextDoorAPIAuth(token))
                    .createDefaultPost()
                    .setBodyText("My first post created via SDK!")
                    .execute();

            System.out.println("Link to created post: " + post.getLinkToPost());
        } catch (APIRequestException e) {
            throw new RuntimeException(e);
        }
    }
}

After executing the code successfully, it will return the Post object, which includes postToLink object, which represents link to the post that we created, to get it use the method getLinkToPost().

documentation

All classes, which are making requests to nextdoor API, are in the api package.

Known bugs

This article is for known bugs that are in fixing progress.

  1. HTTP GET request failed java.lang.RuntimeException: java.lang.RuntimeException: org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1] -- This exception appears because nextdoor API returns HTML page and not JSON, we are waiting for nextdoor to fix this kind of issue (typically throws in displayingcontent package classes).

About

SDK which allows one to make requests to nextdoor more comfortably via Java

Topics

Resources

License

Stars

Watchers

Forks

Packages