SocialHub is a multi social network service's API library written in Java, and can be complied to Objective-C by J2ObjC. and we can also use it with Kotlin and Swift too.
List of SNS
- Twitter ( use library based on twitter4j )
- Facebook ( use library based on facebook4j )
- Slack ( use library based on jslack )
- Mastodon ( use library based on mastodon4j )
- Tumblr ( use library based on jumblr )
- Discord API does not provide the way to write messege api as user to channel.
Most of all libraries are modified (remove complex dependency and unused functions in SocialHub) for compilation to Objective-C with J2ObjC.
Code sample to authorize account and get account information.
/* JAVA */ // 1. Make Authorized Account Object // For Twitter TwitterAuth auth = SocialHub.getTwitterAuth(CONSUMER_KEY, CONSUMER_SECRET); Account account = auth.getAccountWithAccessToken(ACCESS_TOKEN, ACCESS_SECRET); // For Mastodon MastodonAuth auth = SocialHub.getMastodonAuth(HOST); Account account = auth.getAccountWithAccessToken(ACCESS_TOKEN); // 2. Request To SNS (all sns same interface) User user = account.action().getUserMe(); System.out.println(user.getName());
Code sample to get unified timeline comments from account group (two or more accounts).
/* JAVA */ // 1. Make Account Group AccountGroup accounts = new AccountGroup(); accounts.addAccount((Account) twitterAccount); accounts.addAccount((Account) mastodonAccount); // 2. Get Home New Timeline CommentGroup comments = accounts.action().getHomeTimeLine(); // 3. Get Past Timeline CommentGroup pasts = comments.action().getPastComments();
if you want more samples, please see detail documents and test code.
J2ObjC is project aim to compile Java code to Objective-C code. SocialHub is adapted with J2ObjC compilation So, you can use SocialHub as an Objective-C library (also use in Swift) in MacOS or iOS application development. Travis CI compiles SocialHub and make SocialHub CocoaPods Repository. It's easy way to use this repository rather than compiling yourself.
Compile to Objective-C
To compile SocialHub to Objective-C framework, do following instructions. It's only executable on MacOS environment (This file is script of followings.)
Download latest J2ObjC builds and unzip
Set J2ObjC path in
Build Objective-C libraries
Build commands is written in
j2objc.shfile. so execute it or do following commands.
j2objc.gradleis gradle settings to make Objective-C library.
./gradlew -b j2objc.gradle clean :j2objcAssemble -x test
Add dependency in your project
After J2ObjC comple,
cocoapod.specwill be created in
./build/j2objcOutputsfolder, so you write SocialHub dependency in your CocoaPods project's
def j2objc_socialhub pod 'j2objc-SocialHub-debug', :configuration => ['Debug'], :path => '../shared/build/j2objcOutputs' pod 'j2objc-SocialHub-release', :configuration => ['Release'], :path => '../shared/build/j2objcOutputs' end ... NOTE: this line must be added manually for the relevant targets: j2objc_socialhub ...
Use SocialHub in Swift
Make bridging header, and write as following.