Nobody can deny the power of social media in building an audience for your game. I'm going to be writing a few posts detailing the simplest ways I know of for sharing your game via some popular social media sites; today, I'm going to focus on Twitter.
I create almost all of my buttons with NGUI. If you're not using it, I've written a very simple post on getting started with it. If you're using NGUI, you'll call the ShareToTwitter () method in the OnClick () method of the button of your choice, passing in the text you'd like to share. Regardless, you just need to call this method with the text that you'd like to share, hashtags and all.
private const string TWITTER_ADDRESS = "http://twitter.com/intent/tweet";
private const string TWEET_LANGUAGE = "en";
void ShareToTwitter (string textToDisplay)
{
Application.OpenURL(TWITTER_ADDRESS +
"?text=" + WWW.EscapeURL(textToDisplay) +
"&lang=" + WWW.EscapeURL(TWEET_LANGUAGE));
}
So what are we doing here? Well, we're opening a URL, which in this case is the URL that Twitter uses to allow us to post to our account. On a PC, this will open the browser and attempt to post Twitter the textToDisplay parameter. On mobile devices, this will open the Twitter app or the browser, depending on what the user has.
You can build up the textToDisplay parameter however you like; just remember the 140-character limit. Include hashtags, a link, your score, whatever.
I have one more with my game in ios. When the user goes to update their status through the game, they are being redirected to a browser even though they have the twitter app.
ReplyDeletehow can I make it redirect to only the app and not the browser? I am really desperate to find this answer!
I am even willing to pay upto $200 to fix these issues for me.
DeleteI'm not a big iOS guy, but my best guess is that while the Twitter app is installed, Twitter links are not associated with the Twitter app, but with the browser instead. This would be an iOS issue, not an issue with your app.
DeleteThanks a lot! That was very helpful
ReplyDeleteNo problem! Thanks for the feedback.
DeleteThis is awesome :) Any plans for Facebook integration tutorials? I always struggle with this sort of thing.
ReplyDeleteYes! As soon as I have time, that's going to be my next post. I'm glad it helped you out!
DeleteI just posted a simple way to post to Facebook. You can check it out here:
Deletehttp://unity3dtrenches.blogspot.com/2014/07/unity3d-how-to-post-to-facebook-from.html
This made my day! How bout tweeting with a picture ?
ReplyDeleteIm thinking if it could only be done by saving your app image to users gallery
and get it when posting.
I'm thinking the same thing. I'll be addressing that in a future post. Thanks for reading!
DeleteThis is excellent, thanks so much for sharing.
ReplyDeleteDid anyone else have the issue of spaces showing up as + symbols on Twitter?
I am having same issue. Everything works great on Android, and on iOS if twitter is not installed, but on iOS if twitter is installed it loads spaces as + in tweet.
DeleteDid you ever figure this out?
In case anyone else ends up googling this:
DeleteI ended up fixing this by doing the WWW.EscapeURL(textToDisplay) and then replacing the "+" with "%20". It seems to work on both platforms with and without twitter installed as expected.
Hi, well, I try this code but when anybody share on twitter, they can change the text to share. So, How Can I lock this ?
ReplyDeleteThanks!
Unfortunately, you can't. Because we're opening the app itself to handle inputting text via the API, you can pre-form the text, but you can't prevent the user from changing it.
DeleteAnd can we share a screenshot intead ?
DeleteAny idea?
Delete@Alberto: Yes, I'm almost positive you can. I'll be dealing with that in a future post. I just haven't had time to look into it yet.
DeleteOkey, Could you tell me when you make this post ?
DeleteThanks!
Hi again!
DeleteSo, you know when you can make twitter post ?
I wait your answers
You know they do this in their own time and you get it for free, eh? How about a little patience?
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHey guys, just wondering if there is a simple way to check if the person successfully tweeted the tweet?
ReplyDeleteCheers in advance!!
very helpful...Thanks
ReplyDeleteI was wondering if there is a way to post an icon of your app or a custom graphic with your post. Thanks
ReplyDeletehi any one can help me here! i tried the fb post same error like this twitter post, im new to c# here's the class:
ReplyDeleteusing UnityEngine;
using System.Collections;
public class twuittershare : MonoBehaviour {
// Use this for initialization
void OnMouseDown()
{
ShareToTwitter();
}
private const string TWITTER_ADDRESS = "http://twitter.com/intent/tweet";
private const string TWEET_LANGUAGE = "en";
void ShareToTwitter (string textToDisplay)
{
Application.OpenURL(TWITTER_ADDRESS +
"?text=" + WWW.EscapeURL(textToDisplay) +
"&lang=" + WWW.EscapeURL(TWEET_LANGUAGE));
}
}
and found this error:
Assets/twuittershare.cs(9,17): error CS1501: No overload for method `ShareToTwitter' takes `0' arguments
tell me what to do please
When you call ShareToTwitter() you need to have a string value inside the parenthesis.
Deleteplease i need your help answer
ReplyDeleteI don't think you'll find anyone that will write the script for you, but I will tell you that you're getting this error because you're not giving the ShareToTwitter () the parameters it expects. I'd recommend rather than worrying about this specific script, boning up on your basic C# skills, and then coming back to it:
Deletehttps://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx
Good luck!
This works like a charm on PC and Andoid, but unfortunately not on a Mac or iPhone. On these platforms, nothing happens when i press the button in my game. Do you have any idea how this could be?
ReplyDeleteThanks!
Haha I use the same in my game. Simple and does the trick! Respect for taking the time to share it.
ReplyDeleteHave you tried auto-attaching a screenshot though? That's something I've been working on without any success for a while...
For anyone wondering how to share an image with your tweet, just add the meta data to your html file as outlined here -
ReplyDeletehttps://dev.twitter.com/cards/types/summary-large-image
obviously replacing out with your relevant info. twitter will find the meta data and the image will be added automatically.
Thanks
which html file?
Deletehi
ReplyDeletei want to share my link to instagram and google plus by below methode .
private const string TWITTER_ADDRESS = "http://twitter.com/intent/tweet";
private const string TWEET_LANGUAGE = "en";
void ShareToTwitter (string textToDisplay)
{
Application.OpenURL(TWITTER_ADDRESS +
"?text=" + WWW.EscapeURL(textToDisplay) +
"&lang=" + WWW.EscapeURL(TWEET_LANGUAGE));
}
is there a way?
hello ,
ReplyDeleteits possible to share image and text by twitter url