npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-weibosdk

v0.6.4

Published

Cordova Weibo Plugin

Readme

cordova-plugin-weibosdk

Cordova/PhoneGap 插件,用于在混合应用(Hybrid App)中集成微博 SDK,支持微博分享核心功能,适配OHOS平台。

OHOS平台支持分享功能,具体参考API说明

(1),支持分享文本

(2),支持分享沙箱图片,视频(不支持相册图片和视频直接分享)

(3),支持在线图片(实际是插件下载后再分享)

(4),在线视频(不建议直接分享在线视频,因在线视频插件下载后再分享,大视频速度较慢)

支持平台

  • OHOS 5.0+

前置准备

  1. 注册 微博开放平台 账号,创建移动应用

  2. 完善应用信息:

  • OHOS:填写应用包名,上传签名文件等信息(当前开发平台不支持OHOS平台资料填写,请把信息填写在Android中)
  1. 签名信息获取
  • 方法一:在微博开发平台下载鸿蒙SDK,下载后设置签名,签名信息可以填写真实应用的信息,运行SDK Demo,可以在日志中获取签名信息
  • 方法二:在您的应用中,集成鸿蒙SDK的 core.har包,然后根据Demo代码在您的应用中获取签名

安装

通过 HCordova CLI 安装(支持 cordova-openharmony 2.0.0+):

hcordova命令化工具 仓库:OpenHarmony-Cordova/hcordova-cli

基础安装

# 安装hcordova
npm install -g hcordova

# 安装微博插件
hcordova plugin add cordova-plugin-weibosdk 

#指定OHOS安装
hcordova plugin add cordova-plugin-weibosdk --platform ohos

卸载

hcordova plugin remove cordova-plugin-weibosdk 

# 指定OHOS卸载
hcordova plugin remove cordova-plugin-weibosdk --platform ohos

配置说明

OHOS 额外配置

  1. 复制微博SDK的Demo工程的lib/core.har到您的功能对应的目录

  2. 在主工程oh-package.json5中添加core(core是微博的har包,这个命名实在很糟糕,以致于会有很多的异议)的依赖。

{
  "name": "entry",
  "version": "1.0.0",
  "description": "Please describe the basic information.",
  "main": "",
  "author": "",
  "license": "",
  "dependencies": {
    "@magongshou/harmony-cordova": "file:../cordova",
    "core": "file:./lib/core.har"
  }
}
  1. 在主工程中,执行ohpm entry/lib/core.har安装weiboSDK

  2. 修改项目中的EntryAbility的代码,添加微博插件在ArkTS侧监听和初始化:

export default class EntryAbility extends UIAbility {
   onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
      //添加如下代码,初始化微博SDK
        weiboArgs["APP_KEY"] = "3035999986"; //开发平台获取
        weiboArgs["REDIRECT_URL"] = "https://ceshi.tongecn.com"; //回调URL,主要用于授权登录,但是当前授权登录,鸿蒙微博SDK并未真正实现,因此该URL作用不大,但是必须配置
        weiboArgs["SCOPE"] = "email,direct_messages_read,direct_messages_write,friendships_groups_read,friendships_groups_write,statuses_to_me_read,follow_app_official_microblog,invitation_write"; 
        PluginRegisterHandle(this, want, "WeiboAction/WeiboAction", "EntryAbility", JSON.stringify(weiboArgs));
   }
}
  1. 在主工程中添加core(注意core是微博的har包,这是一个微博SDK糟糕的命名)为动态导入,如下:
"runtimeOnly": {
"packages": [
    "core"
]
}

API说明

options说明

|参数|类型|说明| |----|-------|----| |text|string|分享的文本| |image|string|分享的图片,可以是url,base64,沙箱路径| |videoUrl|string|分享的视频,可以沙箱路径,url(不建议直接使用url)|

1. 分享文本

/*
* success 成功分享函数
* failed 分享失败函数
*/
WeiboSDK.shareTextToWeibo(success, failed, options);
//使用示例
 var args = {};
args.text = 'This is a Cordova Plugin';
WeiboSDK.shareTextToWeibo(function () {
    document.getElementById("weiboShareText").innerHTML = "分享成功";
}, function (failReason) {
    document.getElementById("weiboShareText").innerHTML = "分享失败:"+failReason;
}, args);

2. 分享图片

/*
* success 成功分享函数
* failed 分享失败函数
*/
WeiboSDK.shareImageToWeibo(success, failed, options);
//从相册选择一个图片分享到微博
var options = {
    // Some common settings are 20, 50, and 100
    quality: 80,
    destinationType: Camera.DestinationType.DATA_URL,
    // In this app, dynamically set the picture source, Camera or photo gallery
    sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
    encodingType: Camera.EncodingType.JPEG,
    mediaType: Camera.MediaType.PICTURE,
    targetWidth:800,
    targetHeight:600,
    allowEdit: true,
    correctOrientation: true  //Corrects Android orientation quirks
}
navigator.camera.getPicture(function cameraSuccess(imageData) {
    var args = {};
    args.image = "data:image/jpeg;base64,"+imageData;
    WeiboSDK.shareImageToWeibo(function () {
        document.getElementById("weiboShareImageUrl").innerHTML = "分享成功";
    }, function (failReason) {
        document.getElementById("weiboShareImageUrl").innerHTML = "分享失败:"+failReason;
    }, args);
}, function cameraError(error) {
    console.debug("Unable to obtain picture: " + error, "app");
}, options);
//分享在线图片到微博
var args = {};
args.image = 'https://res-static.hc-cdn.cn/cloudbu-site/china/zh-cn/hdhomeportal/logonew.png';
WeiboSDK.shareImageToWeibo(function () {
    document.getElementById("weiboShareImageUrl").innerHTML = "分享成功";
}, function (failReason) {
    document.getElementById("weiboShareImageUrl").innerHTML = "分享失败:"+failReason;
}, args);

3. 分享视频到微博

/*
* success 成功分享函数
* failed 分享失败函数
*/
WeiboSDK.shareToWeibo(success, failed, options);
//从相册选择一个封面图片,从网络下载一个视频分享(生产环境,不建议下载视频分享)
var options = {
    // Some common settings are 20, 50, and 100
    quality: 80,
    destinationType: Camera.DestinationType.FILE_URI,
    // In this app, dynamically set the picture source, Camera or photo gallery
    sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
    encodingType: Camera.EncodingType.JPEG,
    mediaType: Camera.MediaType.PICTURE,
    allowEdit: true,
    cameraDirection:Camera.Direction.FRONT,
    correctOrientation: true  //Corrects Android orientation quirks
}
navigator.camera.getPicture(function cameraSuccess(imageUri) {
    var args = {};
    args.image = imageUri;
    args.videoUrl = "https://vod.chuzhitong.com/Act-ss-mp4-hd/SVID_20250928_140357_1.mp4";
    WeiboSDK.shareToWeibo(function () {
        document.getElementById("weiboShareImageUrl").innerHTML = "分享成功";
    }, function (failReason) {
        document.getElementById("weiboShareImageUrl").innerHTML = "分享失败:"+failReason;
    }, args);
}, function cameraError(error) {
    console.debug("Unable to obtain picture: " + error, "app");
}, options);

许可证

本插件基于 Apache License 2.0 开源,详情见 LICENSE 文件。

官方资源