【HarmonyOS 5】Integrating Weibo Sharing into HarmonyOS Applications

GeorgeGcs
• 阅读 1
  1. Download Weibo Sharing SDK ● Official SDK Website: https://open.weibo.com/wiki/SDK
    ● Download the HarmonyOS SDK demo project package. After completion, the compressed file should appear as: Insert image description here

  2. Modify Project Configuration and Signing

  3. After extracting the package, open the project in DevEco Studio and update the configuration:
    ○ The downloaded project may use outdated signing settings and SDK references, requiring manual adjustments to run successfully.

  4. Cleanup Steps:
    ○ Delete the oh-package-lock.json5 file.
    ○ Remove SDK reference paths in local.properties. Insert image description here
    ○ Delete unused core module references in build-profile.json5. Re-sync the signing configuration using automatic signing. Insert image description here
    ○ Ensure oh-package.json5 devDependencies match your IDE and SDK versions.

  5. Run the Weibo SDK Project and Integrate Sharing Code Insert image description here The demo project demonstrates SDK initialization and sharing functions. Follow these steps for integration:

3.1 Obtain the Weibo SDK Insert image description here

3.2 Initialize the Weibo SDK Initialize via the WBAPI singleton and track the status:
// Index.ets private initSdk() { this.isInit = true; this.mWBAPI = WBAPI.getInstance(); }

3.3 Weibo Sharing API Implementation The sharing page (SharePage.ets) supports three types: text, images, and videos, similar to Android/iOS:
// SharePage.ets private async doWeiboShare() { const message: WeiboMultiMessage = new WeiboMultiMessage();

// 1. Text sharing const textObject = new TextObject(); let text = "I'm sharing text via Weibo client."; if (this.shareText) { text = "Set your sharing content here!"; textObject.text = text; message.textObject = textObject; }

// 2. Multi-image sharing if (this.shareMultiImage) { const multiImage = new MultiImageObject(); try { const uris = new ArrayList(); uris.add(fileUri.getUriFromPath(Utils.getImageCacheFile(getContext()) + "/aaa.png")); // Add more image URIs... multiImage.uriStrs = uris.convertToArray(); } catch (e) { const err = e as BusinessError; Utils.logger.error("zhaojun8", "Multi-image file operation failed: " + err.message); } message.multiImageObject = multiImage; }

// 3. Video sharing if (this.shareVideo) { const videoObj = new VideoSourceObject(); try { const videoFilePath = Utils.getVideoCacheFile(getContext()) + '/eeee.mp4'; const videoUri = fileUri.getUriFromPath(videoFilePath); const coverUri = fileUri.getUriFromPath(Utils.getImageCacheFile(getContext()) + '/cover.png'); videoObj.videoPath = videoUri; videoObj.coverPath = coverUri; } catch (e) { const err = e as BusinessError; Utils.logger.error("zhaojun8", "Video file operation failed: " + err.message); } message.videoSourceObject = videoObj; }

// Execute sharing if (this.mWBAPI) { const listener: WbASListener = { onComplete: () => promptAction.showToast({ message: 'Sharing succeeded', duration: 2000 }), onError: (error: UiError) => promptAction.showToast({ message: 'Sharing failed: ' + error.errorMessage, duration: 2000 }), onCancel: () => promptAction.showToast({ message: 'Sharing canceled', duration: 2000 }) }; this.mWBAPI.shareMessage(this.context, message, listener); } }

Sharing Workflow

  1. After clicking "Share," the app redirects to the Weibo sharing page. Insert image description here
  2. Grant permission to redirect to Weibo (requires the Weibo app installed and logged in). Insert image description here
  3. The sharing result (success/cancel/error) is prompted via a toast.

Key Notes ● SDK Version Compatibility: Ensure the downloaded SDK matches your IDE version.
● File Paths: Use valid URIs for images/videos (e.g., sandbox paths).
● Error Handling: Implement robust error callbacks for network or permission issues. Integrating Weibo sharing into HarmonyOS apps is straightforward—start building share functionality today!

点赞
收藏
评论区
推荐文章
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
GeorgeGcs GeorgeGcs
17小时前
【 HarmonyOS 5 入门系列 】鸿蒙HarmonyOS示例项目讲解
【HarmonyOS5入门系列】鸿蒙HarmonyOS示例项目讲解\鸿蒙开发能力HarmonyOSSDK应用服务鸿蒙金融类应用(金融理财一、前言:移动开发声明式UI框架的技术变革在移动操作系统的发展历程中,UI开发模式经历了从命令式到声明式的重大变革。根据
GeorgeGcs GeorgeGcs
11小时前
从“备胎”到领航者,鸿蒙操作系统的传奇进化
鸿蒙开发能力HarmonyOSSDK应用服务鸿蒙金融类应用(金融理财【HarmonyOS5】2019年,在全球科技产业的风云变幻中,华为正式推出了鸿蒙操作系统(HarmonyOS),这一消息如同一颗重磅炸弹,瞬间吸引了全世界的目光。彼时,外界对鸿蒙的诞生背
GeorgeGcs GeorgeGcs
7小时前
【HarmonyOS 5】Integrating WeChat Sharing into HarmonyOS Applications
1.DownloadHarmonyOSWeChatOpenSDKandDemo1.1WeChatOpenSDKInsertimagedescriptionhereClicktodownload@tencent/wechatopensdk(V1.0.7).1
GeorgeGcs
GeorgeGcs
Lv1
男 · 金融头部企业 · 鸿蒙应用架构师
HarmonyOS认证创作先锋,华为HDE专家,鸿蒙讲师,作者。目前任职鸿蒙应用架构师。 历经腾讯,宝马,研究所,金融。 待过私企,外企,央企。 深耕大应用开发领域十年。 AAE,Harmony(OpenHarmony\HarmonyOS),MAE(Android\IOS),FE(H5\Vue\RN)。
文章
56
粉丝
1
获赞
2