我可以在Unity3D中将文本发布到Twitter,但我需要能够发布照片

时间:2013-05-29 02:34:16

标签: c# twitter unity3d

所以我从Unity资产商店获得了这个免费的插件,在Unity中称为Let's Tweet,它非常适合发布文字,但我无法弄清楚如何使用https://upload.twitter.com/1/statuses/update_with_media.xml

而不是现在正在使用的http://api.twitter.com/1/statuses/update.xml?status= {0}。它是用C#编写的,我真的不知道,我也没有在twitter api上经验丰富。一般来说,我是编码的新手。我正在学习JS。

这个插件已经完成了我认为是与消费者密钥,秘密等交谈的最难的部分。我猜的部分需要改变,但我也可以发送给你整个文件。

private static readonly string PostTweetURL = "http://api.twitter.com/1/statuses/update.xml?status={0}";

    public static IEnumerator PostTweet(string text, string consumerKey, string consumerSecret, AccessTokenResponse response, PostTweetCallback callback)
    {
        if (string.IsNullOrEmpty(text) || text.Length > 140)
        {
            Debug.Log(string.Format("PostTweet - text[{0}] is empty or too long.", text));

            callback(false);
        }
        else
        {
            string url = string.Format(PostTweetURL, UrlEncode(text));
            Dictionary<string, string> parameters = new Dictionary<string, string>();

            parameters.Add("status", text);

            // Need to fill body since Unity doesn't like an empty request body.
            byte[] dummmy = new byte[1];
            dummmy[0] = 0;

            // HTTP header
            Hashtable headers = new Hashtable();
            headers["Authorization"] = GetHeaderWithAccessToken("POST", url, consumerKey, consumerSecret, response, parameters);

            WWW web = new WWW(url, dummmy, headers);
            yield return web;

            if (!string.IsNullOrEmpty(web.error))
            {
                Debug.Log(string.Format("PostTweet - failed. {0}", web.error));
                callback(false);
            }
            else
            {
                string error = Regex.Match(web.text, @"<error>([^&]+)</error>").Groups[1].Value;

                if (!string.IsNullOrEmpty(error))
                {
                    Debug.Log(string.Format("PostTweet - failed. {0}", error));
                    callback(false);
                }
                else
                {
                   callback(true);
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:-1)

试试这个:UniShare,它支持将照片发布到Twitter。此外,它还支持与许多其他社交平台共享,如Facebook,链接等。并支持iOS,Android,Mac。