困った時の自分用メモ

読んだ本を考察してメモったり、自分でいじった物の感想をメモったりする場。週1更新を目指します。

Unityの話~AndroidアプリからTwitter投稿をする1~

仕事で調査したので、メモ。今回は、人のプラグインを使って対応。

okamura0510.jp

github.com

こちらの方の物を参考にして使わせてもらった。

  1. Githubからダウンロード

  2. SocialWorker.unitypackageをインポート

  3. ヒエラルキーに、Assets/SocialWorker/Prefabs/SorcialWorkerを配置。
    SorcialWorker.csがついてるから、たぶん初期化とかしているので、これ配置しないと、うまくいかない。

  4. スクリプトを書く

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TwitterSendTest : MonoBehaviour {

    [SerializeField]Text DebugOutputText;

    private string OutputText = "";

    public void OnClickTwitterSendButton() {
        SWorker.SocialWorker.PostTwitter("Test", "", (SWorker.SocialWorkerResult swres) => {
                string res = "" + swres;
                AddDebugText(res);
            }
        );

    }
    
    private void AddDebugText(string text) {
        OutputText += text + "\n";
        DebugOutputText.text = OutputText;
    }
}

これで、投稿確認できた。

ちなみに、アプリにTwitterがインストールされていないと、エラーメッセージとして、「NotAvailable」が返される。