- Home /
Posting To Twitter From App? - Unity
Hi Jeremy here, and the script below is what i am using to have my users post to Twitter in my mobile game and how it works is when the user taps the screen it opens Twitter in the browser on their mobile device with the text that I specify (text param of "Share" method) asking them to login and let it post the text to their wall. I want it to open the Twitter "app" on their mobile device so they can do it from there instead of doing it from their browser on their mobile device. Note I have Lets Tweet from the unity asset store in this project if that would make a difference. Thank you very much in advance (:
Also this link is where I got this code and may help if you don't understand why its working: http://getencapsulated.com/sharing-results-to-twitter-or-facebook/
using UnityEngine;
using System.Collections;
public class TwitterButton : MonoBehaviour {
const string Address = "http://twitter.com/intent/tweet";
public static void Share(string text, string url,
string related, string lang="en")
{
Application.OpenURL(Address +
"?text=" + WWW.EscapeURL(text) +
"&url=" + WWW.EscapeURL(url) +
"&related=" + WWW.EscapeURL(related) +
"&lang=" + WWW.EscapeURL(lang));
}
void Update () {
if (Input.GetButtonDown("Fire1")) {
Share("Check out this cool game and share on Twitter. Jump Now!", "http://apps.cettatech.com", "", "en");
Debug.Log("Twitter Button Pressed...");
}
}
}
Also a script or something that someone has used to talk to the Twitter API would be very helpful.
Answer by SimenZhor · Nov 21, 2015 at 07:46 PM
I have no experience with this functionality, but I am quite sure Twitter themselves have some sort of functionality for developers to implement into their software after registering as a developer at their site.
Answer by ahaugaa · Jan 30, 2015 at 03:29 AM
I know this doesn't open the Twitter app like you requested, but if you're trying to avoid opening the browser for every post to Twitter, this might help.
I just started working with Let's Tweet (recently updated to work with Twitter API 1.1) and from what I've built off of their example, the user would only have to open a browser once to initially authorize your Unity app to post to their account. From that point on, you can save their necessary account info (for example in PlayerPrefs
) and have direct access to posting tweets from within the Unity app.
If you especially want to use the Twitter app, you could try writing a plugin (for Android) that creates an Intent Chooser dialog with an ACTION_SEND
intent and filter for the Twitter app, as described in this StackOverflow thread.
I'm not familiar with any equivalents for iOS, sorry.