Git Product home page Git Product logo

simpleweibo's Introduction

SimpleWeibo

Android Arsenal Download JitPack javadoc Build Status Gitter Chat

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

javadoc

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.