SimpleWeibo


Source link: https://github.com/8tory/SimpleWeibo

SimpleWeibo

Contributors..

Simple Weibo SDK turns Weibo API into a Java interface with RxJava.

#Demo

Usage

My posts:

weibo = SimpleWeibo.create(activity);
  Observable<Status> myStatuses = weibo.getStatuses();
 myStatuses.take(10).forEach(System.out::println);

logIn (default permissions):

weibo.logIn().subscribe();

logInWithPermissions:

weibo.logInWithPermissions("email", "statuses_to_me_read").subscribe();

Diff

Using Weibo Core SDK:

WeiboParameters params = new WeiboParameters(appId);
 params.put("access_token", accessToken);
 // AbsOpenAPI.KEY_ACCESS_TOKEN // put ...  new AsyncWeiboRunner(context).requestAsync(
"https://api.weibo.com/2" + "/statuses/friends_timeline.json", // AbsOpenAPI.API_SERVER
params,
"GET", // AbsOpenAPI.HTTPMETHOD_GET
new RequestListener() {

  @Override public void onComplete(String json) {

  
}

  @Override public void onWeiboException(WeiboException e) {

  
}

}
 );

Using Weibo SDK:

StatusesAPI statusesApi = new StatusesAPI(context, appId, accessToken);
 statusesApi.friendsTimeline(0L, 0L, 10, 1, false, 0, false, new RequestListener() {

  @Override public void onComplete(String json) {

StatusList statusList = StatusList.parse(response);

List<Status> statuses = statusList.statusList;

// statusAdapter.addAll(statuses);


// statusAdapter.notifyDataSetChanged();

  
}

  @Override public void onWeiboException(WeiboException e) {

  
}

}
 );

After, using SimpleWeibo:

SimpleWeibo.create(activity)

.getStatuses()

.take(10)

.forEach(System.out::println);

Integration

res/values/strings.xml

<string name="weibo_app_id" translatable="false">2045436852</string> <!-- Optional --> <string name="weibo_redirect_url" translatable="false">https://api.weibo.com/oauth2/default.html</string>

AndroidManifest.xml:

<meta-data android:name="com.sina.weibo.sdk.ApplicationId" android:value="@string/weibo_app_id" /> <!-- Optional --> <meta-data android:name="com.sina.weibo.sdk.RedirectUrl" android:value="@string/weibo_redirect_url" />

Activity:

SimpleWeibo weibo;  @Override protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

weibo = SimpleWeibo.create(activity);
 
}
  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {

  super.onActivityResult(requestCode, resultCode, data);

  weibo.onActivityResult(requestCode, resultCode, data);
 
}

Weibo Sharing

Add intent-filter on caller activity:

<intent-filter>
  <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
  <category android:name="android.intent.category.DEFAULT" /> </intent-filter>

Though onActivityResult(..), handle onCreate(Bundle), onNewIntent(Intent), onResponse(BaseResponse) methods:

public MainActivity extends Activity implements IWeiboHandler.Response {

  SimpleWeibo weibo;
  @Override
  public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 weibo = SimpleWeibo.create(this);

weibo.onCreate(this, this, savedInstanceState);

 // Bitmap bitmap = ...;

weibo.share(this, "Hello", bitmap).subscribe(baseResponse -> {

}
);

  
}

@Override
  protected void onNewIntent(Intent intent) {

super.onNewIntent(intent);

weibo.onNewIntent(this, intent);

  
}

  @Override
  public void onResponse(BaseResponse baseResponse) {

weibo.onResponse(baseResponse);

  
}

... 
}

Contribution of add API using RetroWeibo

Ready API:

 @GET("/statuses/friends_timeline.json")
  public abstract Observable<Status> getStatuses(

@Query("since_id") long sinceId,

@Query("max_id") long maxId,

@Query("count") int count,

@Query("page") int page,

@Query("base_app") boolean baseApp,

@Query("trim_user") boolean trimUser,

@Query("feature") int featureType
  );

public Observable<Status> getStatuses() {

// ...
  
}

@GET("/mentions.json")
  public abstract Observable<Status> getMentionedStatuses(

@Query("since_id") long sinceId,

@Query("max_id") long maxId,

@Query("count") int count,

@Query("page") int page,

@Query("filter_by_author") int filterByAuthor,

@Query("filter_by_source") int filterBySource,

@Query("filter_by_type") int filterByType,

@Query("trim_user") boolean trimUser
  );

public Observable<Status> getMentionedStatuses() {

// ...
  
}

@GET("/users/show.json")
  public abstract Observable<User> getUsersById(@Query("uid") long uid);

@GET("/users/show.json")
  public abstract Observable<User> getUsersByName(@Query("screen_name") String screenName);

@GET("/users/domain_show.json")
  public abstract Observable<User> getUsersByDomain(@Query("domain") String domain);

@GET("/users/counts.json")
  public abstract Observable<User> getUsersCount(@Query("uids") long[] uids);

@GET("/comments/show.json")
  public abstract Observable<Comment> getCommentsById(

@Query("id") int id,

@Query("since_id") long sinceId,

@Query("max_id") long maxId,

@Query("count") int count,

@Query("page") int page,

@Query("filter_by_author") int filterByAuthor
  );

public Observable<Comment> getCommentsById(int id) {

// ...
  
}

@GET("/comments/by_me.json")
  public abstract Observable<Comment> getCommentsByMe(

@Query("since_id") long sinceId,

@Query("max_id") long maxId,

@Query("count") int count,

@Query("page") int page,

@Query("filter_by_source") int filterBySource
  );

public Observable<Comment> getCommentsByMe() {

// ...
  
}

public Observable<Comment> getCommentsByMe(int filterBySource) {

// ...
  
}

@GET("/comments/to_me.json")
  public abstract Observable<Comment> getCommentsToMe(

@Query("since_id") long sinceId,

@Query("max_id") long maxId,

@Query("count") int count,

@Query("page") int page,

@Query("filter_by_author") int filterByAuthor,

@Query("filter_by_source") int filterBySource
  );

public Observable<Comment> getCommentsToMe() {

// ...
  
}

public Observable<Comment> getCommentsToMe(int filterByAuthor, int filterBySource) {

// ...
  
}

@GET("/comments/timeline.json")
  public abstract Observable<Comment> getComments(

@Query("since_id") long sinceId,

@Query("max_id") long maxId,

@Query("count") int count,

@Query("page") int page,

@Query("trim_user") boolean trimUser
  );

public Observable<Comment> getComments() {

// ...
  
}

public Observable<Comment> getComments(boolean trimUser) {

// ...
  
}

@GET("/comments/mentions.json")
  public abstract Observable<Comment> getMentionedComments(

@Query("since_id") long sinceId,

@Query("max_id") long maxId,

@Query("count") int count,

@Query("page") int page,

@Query("filter_by_author") int filterByAuthor,

@Query("filter_by_source") int filterBySource
  );

public Observable<Comment> getMentionedComments() {

// ...
  
}

public Observable<Comment> getMentionedComments(int filterByAuthor, int filterBySource) {

// ...
  
}

@GET("/comments/show_batch.json")
  public abstract Observable<Comment> getBatchComments(@Query("cids") long[] cids);

 @RetroWeibo.POST("https://m.api.weibo.com/2/messages/invite.json")
  public abstract Observable<Response> invite(@RetroWeibo.Query("uid") long uid, @RetroWeibo.Query("data") Invitation invitation);

@RetroWeibo.POST("/statuses/update.json")
  public abstract Observable<Status> publishStatus(

@RetroWeibo.Query("status") String content,

@RetroWeibo.Query("long") double longtitude,

@RetroWeibo.Query("lat") double latitude
  );

@RetroWeibo.POST("/statuses/upload.json")
  public abstract Observable<Status> publishStatus(

@RetroWeibo.Query("status") String content,

@RetroWeibo.Query("pic") Bitmap picture,

@RetroWeibo.Query("long") double longtitude,

@RetroWeibo.Query("lat") double latitude
  );

@RetroWeibo.POST("/statuses/upload_url_text.json")
  public abstract Observable<Status> publishStatus(

@RetroWeibo.Query("status") String content,

@RetroWeibo.Query("url") String pictureUrl,

@RetroWeibo.Query("pic_id") String pictureId,

@RetroWeibo.Query("long") double longtitude,

@RetroWeibo.Query("lat") double latitude
  );

public Observable<Status> publishStatus(

String content,

String pictureUrl,

double longtitude,

double latitude
  ) {

// ...
  
}

@RetroWeibo.POST("/comments/create.json")
  public abstract Observable<Comment> publishComment(

@RetroWeibo.Query("comment") String comment,

@RetroWeibo.Query("id") long id,

@RetroWeibo.Query("comment_ori") boolean pingback
  );

public Observable<Comment> publishComment(String comment, long id) {

// ...
  
}

public Observable<Comment> publishComment(String comment, Status status) {

// ...
  
}

public Observable<Comment> publishComment(String comment, String id) {

// ...
  
}

@RetroWeibo.POST("/comments/destroy.json")
  public abstract Observable<Comment> deleteComment(

@RetroWeibo.Query("cid") long commentId
  );

@RetroWeibo.POST("/comments/sdestroy_batch.json")
  public abstract Observable<Comment> deleteComments(

@RetroWeibo.Query("cids") long[] commentIds
  );

@RetroWeibo.POST("/comments/reply.json")
  public abstract Observable<Comment> replyComment(

@RetroWeibo.Query("comment") String comment,

@RetroWeibo.Query("cid") long cid,

@RetroWeibo.Query("id") long id,

@RetroWeibo.Query("without_mention") boolean withoutMention,

@RetroWeibo.Query("comment_ori") boolean pingback
  );

public Observable<Comment> replyComment(

String comment,

long cid,

long id
  ) {

// ...
  
}

public Observable<Comment> replyComment(String comment, Comment parentComment) {

// ...
  
}

@RetroWeibo.POST("/oauth2/revokeoauth2")
  public abstract Observable<Response> revoke();

public Observable<Response> logOut() {

// ...
  
}

More ready APIs ..

Add Model: Status.java:

@AutoJson public abstract class Status implements android.os.Parcelable {

  @Nullable
  @AutoJson.Field(name = "created_at")
  public abstract String createdAt();

  @Nullable
  @AutoJson.Field
  public abstract String id();

  // ... 
}

Demo

Installation

via jitpack:

repositories {

  maven {

url "https://jitpack.io"
  
}
 
}
  dependencies {

  compile 'com.github.8tory.SimpleWeibo:simpleweibo:-SNAPSHOT' 
}

via jcenter:

repositories {

  jcenter() 
}
  dependencies {

  compile 'com.infstory:simpleweibo:1.0.1' 
}

See Also

License

Copyright 2015 8tory, Inc.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Animated icons implemented using AnimatedVectorDrawable.

A morphing toolbar that can expand/collapse at anytime.

An Android TagView library. You can customize awesome TagView by using this library.

This is the Android port of an NES emulator written in Go.

Android Library that shows a beautiful and customizable Material designed dialog with header.

An Intellij platform plugin to transforming SVG to android VectorDrawable.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes