Java quick start

Getting started with MySocialApp is very easy. However, if you have any questions get in touch.

Get your free app

To use your own application follow this startup guide , otherwise you can use our testing app made available to start very quickly.

Testing app

app id: u470584465854a728453
URL: https://u470584465854a728453-api.mysocialapp.io

❗️

Beware of using the testing app

Do not share sensitive information on this instance. In addition, the data is likely to be erased very regularly.

Install the library

Gradle / Maven repository

In your build.gradle or pom.xml script for your application module, add the library repository:

repositories {
    ...
  maven { url 'https://jitpack.io' }
}
<dependency>
  <groupId>com.github.MySocialApp</groupId>
    <artifactId>mysocialapp-java-client</artifactId>
  <version>v0.9.0</version>
</dependency>

Gradle / Maven library

The mysocialapp-java-client library is also available in JitPack repository. Add a dependency element as a child of dependencies with the following in build.gradle or pom.xml:

dependencies {
  implementation 'com.github.MySocialApp:mysocialapp-java-client:v0.17.0'
}
<dependency>
  <groupId>com.github.MySocialApp</groupId>
    <artifactId>mysocialapp-java-client</artifactId>
  <version>v0.17.0</version>
</dependency>

Code examples

Create an account

// Your app or testing app ID
String myAppId = "u470584465854a728453";
MySocialApp msa = new MySocialApp.Builder().setAppId(myAppId).build();

// create user and get session
Session session = msa.blockingCreateAccount("[email protected]", "mySecretPassw0rd", "John");

// get account info
User account = session.getAccount().blockingGet();

System.out.println("My Account ID is " + account.getId());
System.out.println("And it was created at " + account.getCreatedDate());
// Your app or testing app ID
String myAppId = "u470584465854a728453";
MySocialApp msa = new MySocialApp.Builder().setAppId(myAppId).build();

// or the reactive way using RxJava
msa.createAccount("[email protected]", "mySecretPassw0rd", "John") // create user and get session
        .flatMap(mSession -> mSession.getAccount().get()) //  get account info
        .subscribe(mAccount -> {
            System.out.println("My Account ID is " + mAccount.getId());
            System.out.println("And it was created at " + mAccount.getCreatedDate());
        }, {
          // on Failure
        });

See more about configuring the Java library

👍

Gift for testing users

Use your real e-mail address to receive a gift when you register :) In addition, you will see that you can integrate your application with any online service (eg: Mailchimp, Amazon AWS, Google Cloud, Zapier .. ) to react to events (new user, new comment, new photo, new post..) on your app.

Listen for notification events

session.getNotification().addNotificationListener(new AbstractNotificationCallback() {

  @Override
  public void onNewsFeed(@NotNull Feed feed) {
    // called when my friends or someone that I matter published a new content
  }
  
  @Override
  public void onComment(@NotNull Comment comment) {
    // called when someone comments on a post that belongs to me or on which I have interacted
  }
  
  @Override
  public void onLike(@NotNull Like like) {
    // called when someone likes on a post that belongs to me or on which I have interacted
  }
  
  @Override
  public void onMention(@NotNull Feed feed) {
    // called when someone mention me on a post
  }
  
  @Override
  public void onMention(@NotNull Comment comment) {
    // called when someone mention me on a comment
  }
  
  @Override
  public void onConversationMessage(@NotNull ConversationMessage conversationMessage) {
    // called when someone chat with me in private
  }
  
  @Override
  public void onEvent(@NotNull Event event) {
    // called when a new event near to me has been created
  }
  
  // There is much more downstream notifications
});

See more about configuring notification events here

Create post (News Feed / Activity Stream)

A feed post can contain text, image, hashtags, web links, mentions of users. Web links are rewritten and tracked. Publications can be public or visible only from his contacts.

// message with user mention + hash tag
String message = "Hello, my name is [[user:" + myAccount.getId() + "]] this is a post with an image and #hashtag :)";

// build message
FeedPost post = new FeedPost.Builder()
  .setMessage(message) // add text message
  .setImage(new File("/tmp/my_image.jpg")) // add image
  .setVisibility(AccessControl.PUBLIC) // set post visible from all
  .build();

// publish post on public feed
Feed feed = session.getNewsFeed().blockingSendWallPost(post);
// message with user mention + hash tag
String message = "Hello, my name is [[user:" + myAccount.getId() + "]] this is a post with an image and #hashtag :)";

// build message
FeedPost post = new FeedPost.Builder()
  .setMessage(message) // add text message
  .setImage(new File("/tmp/my_image.jpg")) // add image
  .setVisibility(AccessControl.PUBLIC) // set post visible from all
  .build();

// publish post on public feed
session.getNewsFeed().sendWallPost(post).subscribe(feed -> {
  // on Success
}, {
  // on Failure
});

Posts can be published on the public, user, group, event news feed. Dynamic type of feed can be added. (e.g: Product news feed)

Add comment to Post

Each post can receive comments (+ likes) and allow interactions between users. Notifications are sent to warn participants. As well as the feed post, comment can contain text, image, hashtags, web links, mentions of users.

// build comment
CommentPost comment = new CommentPost.Builder()
  .setMessage("Here a comment") // add comment message
  .setImage(new File("/tmp/my_image.jpg")) // add comment image
  .build();

// comment the post
feed.blockingAddComment(comment);
// build comment
CommentPost comment = new CommentPost.Builder()
  .setMessage("Here a comment") // add comment message
  .setImage(new File("/tmp/my_image.jpg")) // add comment image
  .build();

// comment the post
feed.addComment(comment).subscribe(comment -> {
  // on Success
}, {
  // on Failure
});

Create event

Invite users to participate in an event. E.g: notify the users of the final of the World Cup on Sunday, at 9:00pm. You can add a description as well as custom fields to fit your needs.

// Luzhniki Stadium / Moscow
SimpleLocation luzhnikiStadiumLocation = new SimpleLocation(55.709330496, 37.552164458);

// Match start date+time
Calendar start = Calendar.getInstance();
start.set(2018, Calendar.JULY, 15, 21, 0);

// Match end date+time
Calendar end = Calendar.getInstance();
end.set(2018, Calendar.JULY, 15, 22, 30);

// Build event
Event event = new Event.Builder()
  .setName("Soccer World Cup 2018")
  .setDescription("Last soccer world cup match. Go !")
  .setStartDate(start.getTime())
  .setEndDate(end.getTime())
  .setLocation(luzhnikiStadiumLocation)
  .setMaxSeats(10000)
  .setMemberAccessControl(EventMemberAccessControl.PUBLIC)
  .setCoverImage(new File("/tmp/worldcup.jpg"))
  .setCustomFields(soccerCustomFields) // your custom fields
  .build();

// Create event
session.getEvent().blockingCreate(event);
// Luzhniki Stadium / Moscow
SimpleLocation luzhnikiStadiumLocation = new SimpleLocation(55.709330496, 37.552164458);

// Match start date+time
Calendar start = Calendar.getInstance();
start.set(2018, Calendar.JULY, 15, 21, 0);

// Match end date+time
Calendar end = Calendar.getInstance();
end.set(2018, Calendar.JULY, 15, 22, 30);

// Build event
Event event = new Event.Builder()
  .setName("Soccer World Cup 2018")
  .setDescription("Last soccer world cup match. Go !")
  .setStartDate(start.getTime())
  .setEndDate(end.getTime())
  .setLocation(luzhnikiStadiumLocation)
  .setMaxSeats(10000)
  .setMemberAccessControl(EventMemberAccessControl.PUBLIC)
  .setCoverImage(new File("/tmp/worldcup.jpg"))
  .setCustomFields(soccerCustomFields) // your custom fields
  .build();

// Create event
session.getEvent().create(event).subscribe(event -> {
  // on Success
}, {
  // on Failure
});

Possibilities are endless. Check out our readme Java github page for more examples.