• Stars
    star
    381
  • Rank 112,502 (Top 3 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 13 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

新浪微博SDK之iOS版本

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.

More Repositories

1

whisper-subtitles

Apple PodCast Transcription with OpenAI's Whisper
Jupyter Notebook
339
star
2

gpt-games

Build games with GPT
Python
306
star
3

gpt-api

TypeScript
225
star
4

Lucene.Net.Analysis.PanGu

盘古分词(http://pangusegment.codeplex.com/ ),由于老版本不支持最新Lucene.Net 3.0.3,对其进行了升级,可以支持最新的Lucene.Net 3.0.3。可以直接NuGet安装。
C#
172
star
5

twitter-virtual-scroller

Twitter's infinite scrolling component VirtualScroller
TypeScript
73
star
6

recoil-paint

The missed demo project for recoiljs
JavaScript
68
star
7

angular-markdown-editor

Markdown editor with AngularJS.
JavaScript
46
star
8

neuron-explainer-paper

https://openaipublic.blob.core.windows.net/neuron-explainer/paper/index.html
JavaScript
42
star
9

express-seed

An empty website using nodejs + express + handlerbars + sass + bower + grunt + mysql.
CSS
37
star
10

Lucene.Net.Analysis.MMSeg

基于Chih-Hao Tsai 的 MMSeg 算法(http://technology.chtsai.org/mmseg/ )实现的中文分词器,并实现 lucene.net 的 analyzer以方便在Lucene.Net中使用。本代码来源于*王员外*(http://www.cnblogs.com/land/archive/2011/07/19/mmseg4j.html)基于Java版的翻译,升级到了最新版Lucene.Net (≥ 3.0.3),并包含简单示例和NuGet安装包。
C#
36
star
11

OLImageDownloader

图片下载和缓存封装 Image cache and download
Objective-C
29
star
12

translations

25
star
13

bbcode-to-react

A utility for turning raw BBCode into React elements.
JavaScript
24
star
14

redux-demo

A redux demo
JavaScript
21
star
15

AppPngDecoder

Decode iPhone png files
6
star
16

fetchog

A node npm for fetching a given URL, returns its title, description, image.
JavaScript
6
star
17

angular-ui-gridster

Angular Gridster.js directive
JavaScript
5
star
18

The-practice-of-iPhone-application-development

Objective-C
5
star
19

atom-state

A state management library for React
TypeScript
5
star
20

auto-link

Replace URLs in text with HTML links, ignore the URLs within a href/pre tag.
JavaScript
5
star
21

electron-boilerplate-react

Boilerplate to kickstart creating an electron app with Electron, React, Gulp, Less.
JavaScript
4
star
22

hipchat-js

JavaScript
3
star
23

reactree

React tree-view component
JavaScript
3
star
24

WordCounter

Count the words
C#
2
star
25

csc471

Swift
1
star