GithubHelp home page GithubHelp logo

weibosdk's Introduction

WeiboSDK

新浪微博SDK,基于v2版API接口,对认证和请求进行了简要封装,

备注: 需要 iOS 6.0+,需要使用ARC

安装

方法一:静态库引用

添加依赖项

  • 在你项目App的target设置, 找到 "Build Phases" 选项并打开 "Link Binary With Libraries":
  • 点击 "+" 按钮,然后点击 "Add Other...", 浏览到WeiboSDK根目录的"build"目录,选择 "WeiboSDK.framework" 并添加到项目中
  • 在你项目设置, 找到 "Build Settings" 选项,找到 "Other Linker Flags" 项,添加值 -ObjC

引用头文件

在需要使用WeiboSDK的代码中引用头文件。

#import <WeiboSDK/WeiboSDK.h>

方法二:代码引用

添加项目文件

到将项目根目录下的"src"目录,将下面的 "WeiboSDK" 目录拷贝到项目中即可。

引用头文件

在需要使用WeiboSDK的代码中引用头文件。

#import "WeiboSDK.h"

使用说明

初始化Weibo对象实例

在使用前,要先初始化Weibo对象实例,设置您自己申请的AppKey和AppSecret

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	// ...
    Weibo *weibo = [[Weibo alloc] initWithAppKey:@"您的AppKey" withAppSecret:@"您的AppSecret" withRedirectURI:@"您的AppSecret RedirectURI"];
    [Weibo setWeibo:weibo];
    // ...
    return YES;
}

通过微博SDK访问微博服务

登录认证相关

判断是否登录

if (![Weibo.weibo isAuthenticated]) {
    // 没有登录
}
else {
    // 已经登录成功
}

获取当前登录用户

WeiboAccount *account = [Weibo.weibo currentAccount];
User *user = account.user; // current user

注销登录

[Weibo.weibo signout];

登录

弹出登录界面登录,并对登录结果进行处理。

[Weibo.weibo authorizeWithCompleted:^(WeiboAccount *account, NSError *error) {
    if (!error) {
        NSLog(@"成功登录,登录名: %@", account.user.screenName);
    }
    else {
        NSLog(@"登录失败: %@", error);
    }
}];

微博相关

查询关注用户的微博

通过queryTimeline系列方法可以去查询微博列表,根据参数可以返回不同结果,使用Block对返回结果进行处理

[Weibo.weibo queryTimeline:StatusTimelineFriends count:50 completed:^(NSMutableArray *statuses, NSError *error) {
    if (error) {
        NSLog(@"获取失败,error:%@", error);
    }
    else {
        NSLog(@"获取成功,微博条数:%d", self.statuses.count);
    }
}];

发新微博

通过Weibo实例中的newStatus方法可以发表微博

不带附件发微博

[weibo newStatus:@"test weibo" pic:nil completed:^(Status *status, NSError *error) {
    if (error) {
        NSLog(@"failed to post:%@", error);
    }
    else {
        NSLog(@"success: %lld.%@", status.statusId, status.text);
    }
}];

带附件发微博

NSData *img = UIImagePNGRepresentation([UIImage imageNamed:@"Icon"]);
[weibo newStatus:@"test weibo with image" pic:img completed:^(Status *status, NSError *error) {
    if (error) {
        NSLog(@"failed to upload:%@", error);
    }
    else {
        StatusImage *statusImage = [status.images objectAtIndex:0];
        NSLog(@"success: %lld.%@.%@", status.statusId, status.text, statusImage.originalImageUrl);
    }
}];

项目参考代码

Licenses

All source code is licensed under the MIT License.

weibosdk's People

Contributors

jakelin avatar jimliu avatar saiday avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

weibosdk's Issues

In WeiboSDK is how to deal with UIPasteboard crash, thank you!

Hi, JimLiu
In the use of Weibo SDK, I also met a problem, but not Weibo SDK problem, and now I have a problem in my own project,
I used openudid this library, it has a method “+ (NSString*) valueWithError: (NSError * * *) error”; in the use of time, there is a certain probability crash, in stackoverflow I found corresponding ending program, but the program is not very suitable, he needs to increase -objc、 all_load,But my project is the use of UnionPay and other static libraries, will generate duplicate symbols. Address: (http://stackoverflow.com/questions/27017908/uipasteboard-accessibilityusequickspeakpasteboard-unrecognized-selector-sen).

Therefore, I want to ask you in WeiboSDK is how to deal with, thank you!

WeiboClient getUser , parameter type should be long long

The type for user id in the sdk is INT now. Some users with long user id( who register Sina recently) will not be able to use functionality like getUser( get screenName , user information etc. ) I met this problem when using the framework to develop my application. It fails to get user information( no response from sina server), after i changed the parameter type to long long, it works well for getUser.

Where to set Redirect URL.

I am using sample code "PublicTimelineSample" I have set redirect URL on Project setting at weibo because my Android app uses redirect URL, Now I also need to set this for iOS. How can I do this.

Thanks.

偶发崩溃。

今天项目崩溃。抓包找到其中有个接口heyiyang.cn引起的应用崩溃。但没有崩溃信息和记录。
项目本身是没有请求这个接口的。
我在注释掉微博代码后,抓包没了这个接口。再重新打开微博相关代码后,也抓不到这个接口了。具体的定位工作打断了。想问问作者清楚这个接口的作用么?

Need x86_64 support

Hi,

最近在使用您的WeiboSDK开发一个App. 之前在Xcode5的iOS模拟器上是运行正常的,但是今天升级Xcode6后发现WeiboSDK似乎不支持x86_64的设备。

建议

楼主,能不能不要放那么多demo 在里面,我一打开真不知道是哪一个.还有api文档总得有吧?实例程序总得有吧?我是初学者.建议楼主谢谢

获取用户email

请问访问用户时,怎么获取用户email?User.h 没有“email”

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.