Skip to content

Instantly share code, notes, and snippets.

@dddnuts
Last active August 19, 2016 13:36
Show Gist options
  • Save dddnuts/17cfe4cb78c4fe751803f88f769397ad to your computer and use it in GitHub Desktop.
Save dddnuts/17cfe4cb78c4fe751803f88f769397ad to your computer and use it in GitHub Desktop.
Log in on Twitter with Fabric Unity SDK
public void GetHomeTimeline()
{
var url = "https://api.twitter.com/1.1/statuses/home_timeline.json";
var session = Twitter.Session;
var oauth = OAuth.OAuthRequest.ForProtectedResource("GET",
Environments.TwitterConsumerKey,
Environments.TwitterConsumerSecret,
session.authToken.token,
session.authToken.secret);
oauth.RequestUrl = url;
var header = new Dictionary<string, string>
{
{ "Authorization", oauth.GetAuthorizationHeader() }
};
UniRx.ObservableWWW.Get(url, header).Subscribe(x =>
{
Debug.Log(x);
}, ex =>
{
Debug.Log(ex);
});
}
using UnityEngine;
using Fabric.Twitter;
public class SceneController : MonoBehaviour
{
public void LogInOnTwitter()
{
var session = Twitter.Session;
if (session != null)
{
OnTwitterLogInSuccess(session);
return;
}
Twitter.LogIn(OnTwitterLogInSuccess, OnTwitterLogInFailure);
}
public void LogOutFromTwitter()
{
Twitter.LogOut();
}
private void OnTwitterLogInSuccess(TwitterSession session)
{
// TODO: Show account.
}
private void OnTwitterLogInFailure(ApiError error)
{
// TODO: Show error.
}
}
public void TweetScreenshot(string imageURL)
{
var card = new AppCardBuilder()
.ImageUri(imageURL)
.GooglePlayId("your.app.identifier")
.IPhoneId("YOURAPPNUMBER")
.IPadId("YOURAPPNUMBER");
Twitter.Compose(Twitter.Session, card);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment