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.
Most of all libraries are modified (remove complex dependency and unused functions) for compilation to Objective-C with J2ObjC.
- Discord
- Discord API does not provide the way to write message api as user to channel.
- Instagram
- Instagram API is duplicated, and new Graph API is business use.
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 an easy way to use this repository rather than compiling yourself.
To compile SocialHub to Objective-C framework, do next instructions. It's only executable on MacOS environment (This file is script of followings.)
-
Download latest J2ObjC builds and unzip
-
Set J2ObjC path in
local.properties
filej2objc.home=${PATH}
-
Build Objective-C libraries
Build commands is written in
j2objc.sh
file. so execute it or do next instructions.j2objc.gradle
is gradle settings to make Objective-C library../gradlew -b j2objc.gradle clean :j2objcAssemble -x test
-
Add dependency in your project
After J2ObjC compile,
cocoapod.spec
will be created in./build/j2objcOutputs
folder, so you write SocialHub dependency in your CocoaPods project'sPodfile
likedef 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.
#include "SocialHubHeader.h"
- iOS: SocialHub
- This library is converted to Objective-C and used in Swift.
Twitter: @uakihir0
GitHub: uakihir0
MIT