Search code examples
androidapiwechat

Post Moments with Wechat API on Android


I created an app with the Wechat API. I try to post on my user's wall. I can publish on Wechat moments successfully on iOS (with the notice saying the app was not approved yet). However on Android, nothing happened.

Here is my code:

  private IWXAPI api;

  api = WXAPIFactory.createWXAPI(this, Constants.WECHAT_APP_ID);
  api.registerApp(Constants.WECHAT_APP_ID);

  String text = "Post on Wechat Wall";
  WXTextObject textObj = new WXTextObject();
  textObj.text = text;

  WXMediaMessage msg = new WXMediaMessage();
  msg.mediaObject = textObj;
  msg.description = text;
  boolean isChecked = false; // true

  SendMessageToWX.Req req = new SendMessageToWX.Req();
  req.transaction = buildTransaction("text"); 
  req.message = msg;
  req.scene = isChecked ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;

  api.sendReq(req);
  finish();

ps : Wechat didn't approve the app yet (submitted it 1 month ago). Could it be one of the reason?


Solution

  • The problem wasn't my code, but the platform where I submitted it.

    I submitted to dev.wechat.com (english version of the developer platform), even if the docs looks/ up to date, the SDK for iOS and Android are not. And your submission will never be reviewed (5 months after the submissions still no sign of activity).

    Solution :

    Create an account on the Chinese version of the developer platform (open.weixin.qq.com, then submit your app on it. It's exactly the same fields and order as the english platform. Google translate will be your best friend here.

    I got my application approved after 3 business days.