Last active
August 19, 2016 13:36
-
-
Save dddnuts/17cfe4cb78c4fe751803f88f769397ad to your computer and use it in GitHub Desktop.
Log in on Twitter with Fabric Unity SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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