乐趣区

关于数据挖掘:ShareSDK-for-Flutter

前言

这是一个基于 ShareSDK 性能的扩大的 Flutter 插件。应用此插件可能帮忙您在应用 Flutter 开发利用时, 疾速地实现社会化性能
, 例如第三方受权登录, 获取用户信息以及社交平台的分享等性能。
Demo 例子:https://github.com/MobClub/ShareSDK-For-Flutter

开始集成

引入插件

https://pub.dev/packages/sharesdk_plugin
在 pubspec.yaml 文件中退出上面依赖
dependencies:
mobcommonlib:
sharesdk_plugin:
而后执行:flutter packages get 导入 package**

在你的 dart 工程文件中,导入上面头文件,开始应用**
import ‘package:sharesdk_plugin/sharesdk_plugin.dart’;

iOS 端集成配置

iOS 端自定义须要导入的分享平台(非必须)

iOS : 这个文件里默认有咱们的一些支流平台,如果须要减少平台,或者缩小平台,你须要从新编辑 sharesdk_plugin.podspec 文件设置 dependency,具体反对的平台能够参阅 pod search mob_sharesdk 或者参考 官网文档

To learn more about a Podspec see http://guides.cocoapods.org/s…

Pod::Spec.new do |s|
s.name = ‘sharesdk_plugin’
s.version = ‘1.1.0’
s.summary = ‘Flutter plugin for ShareSDK.’
s.description = <<-DESC
ShareSDK is the most comprehensive Social SDK in the world,which share easily with 40+ platforms.

                   DESC

s.homepage = ‘http://www.mob.com/mobService…’
s.license = {:file => ‘../LICENSE’}
s.author = {‘Mob’ => ‘mobproduct@mob.com’}
s.source = {:path => ‘.’}
s.source_files = ‘Classes/*/
s.public_header_files = ‘Classes/*/.h’
s.dependency ‘Flutter’
s.dependency ‘mob_sharesdk’
s.dependency ‘mob_sharesdk/ShareSDKExtension’
s.dependency ‘mob_sharesdk/ShareSDKUI’
s.dependency ‘mob_sharesdk/ShareSDKPlatforms/QQ’
s.dependency ‘mob_sharesdk/ShareSDKPlatforms/SinaWeibo’
s.dependency ‘mob_sharesdk/ShareSDKPlatforms/WeChat’
s.dependency ‘mob_sharesdk/ShareSDKPlatforms/Facebook’
s.dependency ‘mob_sharesdk/ShareSDKPlatforms/Twitter’
s.static_framework = true

s.ios.deployment_target = ‘8.0’
end
改好了之后,cd 到 Xcode 目录下,从新 pod update 即可!

初始化 SDK

配置初始化咱们 SDK 的 AppKey
在我的项目工程的 Info.plist 中如图减少 MOBAppKey 和 MOBAppSecret 两个字段

配置平台的 URL SCheme 和白名单

请参考原生文档里的 第四点配置 XCode 我的项目 里的 URL Scheme 配置 白名单配置

第三方平台初始化

增加初始化代码
@override

void initState() {
  // TODO: implement initState
  super.initState();

  ShareSDKRegister register = ShareSDKRegister();
  register.setupWechat("wx617c77c82218ea2c", "c7253e5289986cf4c4c74d1ccc185fb1", "https://70imc.share2dlink.com/");
  register.setupSinaWeibo("568898243", "38a4f8204cc784f81f9f0daaf31e02e3", "http://www.sharesdk.cn", "https://70imc.share2dlink.com/");
  register.setupQQ("100371282", "aed9b0303e3ed1e27bae87c33761161d");
  register.setupFacebook("1412473428822331", "a42f4f3f867dc947b9ed6020c2e93558", "shareSDK");
  register.setupTwitter("viOnkeLpHBKs6KXV7MPpeGyzE",
    "NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey", "http://mob.com");
  register.setupLinkedIn("46kic3zr7s4n", "RWw6WRl9YJOcdWsj", "http://baidu.com");
  SharesdkPlugin.regist(register);
}

Android 端集成配置

从新编辑 build.gradle
Android : 你须要从新编辑 build.gradle, mobsdk.gradle 文件来抉择你须要应用的平台,具体反对的平台能够参阅 官网技术文档
MobSDK {

    appKey "moba6b6c6d6"
    appSecret "b89d2427a3bc7ad1aea1e1e8c1d36bf3"

    ShareSDK {

        devInfo {
            QQ {
                id 7
                sortId 7
                appId "100371282"
                appKey "aed9b0303e3ed1e27bae87c33761161d"
                shareByAppClient true
                bypassApproval false
                enable true
                }

            SinaWeibo {
                id 1
                sortId 1
                appKey "568898243"
                appSecret "38a4f8204cc784f81f9f0daaf31e02e3"
                callbackUri "http://www.sharesdk.cn"
                shareByAppClient true
                enable true
                }

            Wechat {
                id 4
                sortId 4
                appId "wx4868b35061f87885"
                appSecret "64020361b8ec4c99936c0e3999a9f249"
                userName "gh_afb25ac019c9"
                path "pages/index/index.html?id=1"
                withShareTicket true
                miniprogramType 0
                bypassApproval false
                enable true
                }

            Facebook {
                id 8
                sortId 8
                appKey "1412473428822331"
                appSecret "a42f4f3f867dc947b9ed6020c2e93558"
                callbackUri "https://mob.com"
                shareByAppClient true
                enable true
            }

            Twitter {
                id 9
                sortId 9
                appKey "viOnkeLpHBKs6KXV7MPpeGyzE"
                appSecret "NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey"
                callbackUri "http://mob.com"
                shareByAppClient true
                enable true
            }
        }
    }
}

API 接口调用

回传用户隐衷受权后果 (submitPrivacyGrantResult)

/**

  • 回传用户隐衷受权后果
  • @param status 用户是否批准隐衷协定
  • @param result 默认传 null
    */

Mobcommonlib.submitPolicyGrantResult(bool status, Function(bool)? result)

例:
Mobcommonlib.submitPolicyGrantResult(true, null);
ShareSDK 性能接口应用

受权(auth)

void authToWechat(BuildContext context) {

SharesdkPlugin.auth(
    ShareSDKPlatforms.wechatSession, null, (SSDKResponseState state,
    Map user, SSDKError error) {showAlert(state, user != null ? user : error.rawData, context);
});

}

获取用户信息(getUserInfo)

void getUserInfoToWechat(BuildContext context) {

SharesdkPlugin.getUserInfo(
    ShareSDKPlatforms.wechatSession, (SSDKResponseState state,
    Map user, SSDKError error) {showAlert(state, user != null ? user : error.rawData, context);
});

}
ShareSDKPlatforms.wechatSession 这里以微信平台受权作为示例。

调用九宫格分享(showMenu)

setGeneral 内的办法程序及阐明:

SSDKMap params = SSDKMap()

  ..setGeneral(
      "title",
      "text",
      ["http://wx3.sinaimg.cn/large/006nLajtly1fpi9ikmj1kj30dw0dwwfq.jpg"],
      "http://wx3.sinaimg.cn/large/006nLajtly1fpi9ikmj1kj30dw0dwwfq.jpg",
      "","http://www.mob.com/","http://wx4.sinaimg.cn/large/006WfoFPly1fw9612f17sj30dw0dwgnd.jpg","http://i.y.qq.com/v8/playsong.html?hostuin=0&songid=&songmid=002x5Jje3eUkXT&_wv=1&source=qq&appshare=iphone&media_mid=002x5Jje3eUkXT","http://f1.webshare.mob.com/dvideo/demovideos.mp4","",
      SSDKContentTypes.webpage);
SharesdkPlugin.showMenu(null, null, params, (SSDKResponseState state,
    ShareSDKPlatform platform,
    dynamic userData,
    dynamic contentEntity,
    SSDKError error) {showAlert(state, error.rawData, context);
});
独自分享第三方平台(share)

如下所示,替换 share 办法内 ShareSDKPlatforms.wechatSession 第三方平台名称,即可独自分享不同的平台;具体第三方平台名称能够参考如下;
// 独自公共分享
SSDKMap params = SSDKMap()

  ..setGeneral(
      "h5.yoto.fun",
      "text",
      ["http://pic28.photophoto.cn/20130818/0020033143720852_b.jpg"],
      "","",
      "http://mob.com",
      "","",
      "","",
      SSDKContentTypes.image);

SharesdkPlugin.share(ShareSDKPlatforms.wechatSession, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {showAlert(state, error.rawData, context);
});

独自分享 QQ
不须要的参数传 null 即可

setQQ

SSDKMap params = SSDKMap()

  ..setQQ(
      "text",
      "title",
      "http://m.93lj.com/sharelink?mobid=ziqMNf",
      "","",
      "","",
      "","http://wx4.sinaimg.cn/large/006tkBCzly1fy8hfqdoy6j30dw0dw759.jpg","",
      "","http://m.93lj.com/sharelink?mobid=ziqMNf","",
      "",
      SSDKContentTypes.webpage,
      ShareSDKPlatforms.qq);
SharesdkPlugin.share(ShareSDKPlatforms.qq, params, (SSDKResponseState state,
    dynamic userdata, dynamic contentEntity, SSDKError error) {showAlert(state, error.rawData, context);
});

独自分享微博
setSina

SSDKMap params = SSDKMap()

  ..setSina(
      "text",
      "title",
      ["http://download.sdk.mob.com/web/images/2019/07/30/14/1564468183056/750_750_65.12.png"],
      "","http://www.mob.com/",
      0.0,
      0.0,
      "",
      false,
      "http://wx4.sinaimg.cn/large/006WfoFPly1fq0jo9svnaj30dw0dwdhv.jpg",
      "",
      SSDKContentTypes.auto);
SharesdkPlugin.share(ShareSDKPlatforms.sina, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {showAlert(state, error.rawData, context);
});

微博分享卡片模式
setSinaLinkCard

linkcard 类型如下参数,都不能为空

SSDKMap params = SSDKMap()

  ..setSinaLinkCard(
      "linkcard_text",
      "linkcard_title",
      "http://www.mob.com/",
      "全新品牌,优质服务",
      "http://wx4.sinaimg.cn/large/006WfoFPly1fq0jo9svnaj30dw0dwdhv.jpg",
      "120",
      "120");
SharesdkPlugin.share(ShareSDKPlatforms.sina, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {showAlert(state, error.rawData, context);
});

独自分享推特

独自分享 facebook

分享小程序参数
setWeChatMiniProgram

分享到微信
setWechat

分享到绿洲
setOasis

SSDKMap params = SSDKMap()

  ..setOasis(
      "title",
      "text",
      null,
      "http://wx4.sinaimg.cn/large/006tkBCzly1fy8hfqdoy6j30dw0dw759.jpg",
      "","",
      SSDKContentTypes.image);

SharesdkPlugin.share(ShareSDKPlatforms.oasis, params,
    (SSDKResponseState state, dynamic userdata, dynamic contentEntity,
        SSDKError error) {showAlert(state, error.rawData, context);
});
新增对原生 FacebookSDK 的反对(SSDKFacebookShareType

新增跳转到原生分享和在 app 内分享

class SSDKFacebookShareTypes extends Object {
static SSDKFacebookShareType get native => SSDKFacebookShareType(value: 1);
static SSDKFacebookShareType get sheet => SSDKFacebookShareType(value: 2);
}

Flutter iOS 端注意事项

因为插件更新,SDK 的 Pod 依赖被替换,Flutter 自身写入 Pod 文件不会先执行删除原有依赖,导致可能会呈现原有本地库仍然存在,请查看 Pod 文件夹下文件,间接手动删除 mob_shareSDK 以及 MOBFoundation 文件即可,如有疑难,请间接通过官网和咱们分割。

退出移动版