WordPress有客户端么,seo外贸网站,遂宁市住房和城乡建设局网站,商务网站建设策略创建应用
1.登录Twitter控制台并通过认证
2.点击Developer Portal进入Twitter后台
3.点击Sign up for Free Account创建应用
4.配置应用信息
以下为创建过程示例#xff0c;图中信息仅为示例#xff0c;创建时请按照真实信息填写#xff0c;否则无法正常使用。 权限申请…创建应用
1.登录Twitter控制台并通过认证
2.点击Developer Portal进入Twitter后台
3.点击Sign up for Free Account创建应用
4.配置应用信息
以下为创建过程示例图中信息仅为示例创建时请按照真实信息填写否则无法正常使用。 权限申请
Twitter分享和授权需要申请权限以及配置回调地址 集成使用
获取配置
客户端在使用Twitter平台之前需要先获取Twitter为应用分发的Client ID、Client Secret、Callback URI / Redirect URL。 Android
SDK集成
在集成Twitter相关能力之前请先按照ShareSDK集成指南完成ShareSDK的集成
appKey的值对应Twitter平台的Client IDappSecret的值对应Twitter平台的Client SecretcallbackUri的值对应Twitter平台的Callback URI / Redirect URL
MobSDK {appKey xxxxxxxxxxxxxappSecret xxxxxxxxxxxxxxxxShareSDK {devInfo {Twitter {appKey xxxxxxxxxxxxxxxxappSecret xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxcallbackUri xxxxxxxxxxxxxxxxIsUseV2 trueshareByAppClient truebypassApproval trueenable true} }}
}分享示例
代码
以下代码示例分享图片和文字至Twitter
Platform.ShareParams shareParams new Platform.ShareParams();
shareParams.setText(测试文本);
shareParams.setImageUrl(http://pic28.photophoto.cn/20130818/0020033143720852_b.jpg);
Platform platform ShareSDK.getPlatform(Twitter.NAME);
//设置分享事件回调注回调放在不能保证在主线程调用不可以在里面直接处理UI操作
platform.setPlatformActionListener(new PlatformActionListener() {public void onError(Platform platform, int arg1, Throwable throwable) {//失败的回调arg:平台对象arg1:表示当前的动作arg2:异常信息Log.d(ShareSDK, onError ---- 分享失败 throwable.toString());}public void onComplete(Platform platform, int arg1, HashMap hashMap) {//分享成功的回调Log.d(ShareSDK, onComplete ---- 分享成功);}public void onCancel(Platform platform, int arg1) {//取消分享的回调Log.d(ShareSDK, onCancel ---- 取消分享);}
});
platform.share(shareParams);效果图 授权示例
代码
Platform platform ShareSDK.getPlatform(Twitter.NAME);
platform.setPlatformActionListener(new PlatformActionListener() {Overridepublic void onError(Platform platform, int arg1, Throwable throwable) {// TODO 返回授权失败错误码arg2.printStackTrace();Log.e(ShareSDK,登录失败throwable.toString());}Overridepublic void onComplete(Platform platform, int arg1, HashMapString, Object hashMap) {// TODO 授权成功后获取信息操作等Log.e(ShareSDK,platform.getDb().exportData());Log.e(ShareSDK,hashMap.toString());}Overridepublic void onCancel(Platform platform, int arg1) {// TODO 取消回调Log.e(ShareSDK,登录取消);}
});
platform.showUser(null);返回信息示例
在ShareSDK成功回调中调用 platform.getDb().exportData()将返回以下信息
{resume: null,favouriteCount: null,gender: 2,icon: null,snsregat: 0,snsUserUrl: https://twitter.com/null,userID: 0,token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,shareCount: null,secretType: 0,nickname: null,name: xxx,id: xxxxxxxxxxxxxxx,followerCount: null,username: xxxxxxxxxxxxxxxxx
}iOS
SDK集成
在集成微博相关能力之前请先按照ShareSDK集成指南完成ShareSDK的集成。
配置URL Scheme
打开项目的Info选项然后选择URL Types添加URL Scheme配置 twitterkit-Twitter的ClientID例如twitterkit-xxxxxxxxxxxxxxx 配置白名单
(1)在项目的info.plist中添加Queried URL Schemes类型为Array (2)添加一个需要支持的项目类型为字符串类型twitter需要添加的白名单为twitterauth 初始化SDK
在使用Twitter能力之前需要先对其初始化其中setupTwitterWithKey的值对应Twitter平台中的Client IDsecret对应Twitter平台中的Client SecretredirectUrl对应Twitter平台中的Callback URI / Redirect URL
[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {[platformsRegister setupTwitterWithKey:XXXXXXXXXXX secret:XXXXXXXXXXXXXXXX redirectUrl:XXXXXXXXXXXX];
}分享示例
代码
以下代码示例分享图片至Twitter
#import ShareSDK/ShareSDK.h
NSMutableDictionary * shareParams [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:Jshuoh images:http://download.sdk.mob.com/web/images/2019/07/30/14/1564468183056/750_750_65.12.pngurl: niltitle:Im Not Thetype:SSDKContentTypeImage];
[ShareSDK share:SSDKPlatformTypeTwitter parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {if (state SSDKResponseStateSuccess){NSLog(分享成功);}if (state SSDKResponseStateFail){NSLog(失败----%,error.description);}if (state SSDKResponseStateCancel){NSLog(取消);}
}]; 效果图 授权示例
代码
[ShareSDK authorize:SSDKPlatformTypeTwittersettings:nilonStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {if (state SSDKResponseStateSuccess){NSLog(rawData---%,user.rawData);//用户信息打印NSLog(credential---%,[user.credential rawData]);//授权信息打印}if (state SSDKResponseStateFail){NSLog(%,error.description);}if (state SSDKResponseStateCancel){NSLog(取消);;}
}];返回信息示例
user.rawData返回信息为
{id XXXXXXX;name XXXXXXX;username XXXXXX;
}[user.credential rawData]返回信息为
{access_token XXXXXXXXXXXXXX;expires_in 7200;scope tweet.write users.read tweet.read;token_type bearer;