Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: twitter-archive/twitter-kit-unity
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1.1
Choose a base ref
...
head repository: twitter-archive/twitter-kit-unity
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 13 files changed
  • 4 contributors

Commits on Aug 11, 2017

  1. Add success and failure callback to Twitter#Compose(...)

    Eric Frohnhoefer authored and Adam Cummings committed Aug 11, 2017
    Copy the full SHA
    f2f1a57 View commit details
  2. Add callbacks for Tweet Composer on Android

    Adam Cummings committed Aug 11, 2017
    Copy the full SHA
    482c94a View commit details
  3. Add cancel compose tweet callback for iOS

    Adam Cummings committed Aug 11, 2017
    Copy the full SHA
    045ab41 View commit details
  4. Update download ios frameworks script

    Adam Cummings committed Aug 11, 2017
    Copy the full SHA
    5e02819 View commit details
  5. Update README.md

    Adam Cummings committed Aug 11, 2017
    Copy the full SHA
    f3c7285 View commit details

Commits on Aug 28, 2017

  1. Update TwitterDemo.cs to call LoginCompleteWithCompose after login, a…

    …dd comment for LoginCompleteWithEmail
    
    Differential Revision: https://phabricator.twitter.biz/D83606
    Adam Cummings committed Aug 28, 2017
    Copy the full SHA
    ba9e47c View commit details
  2. Ensure Login view is presented on top of the rootViewController

    Gabor Vass authored and Adam Cummings committed Aug 28, 2017
    Copy the full SHA
    da19732 View commit details
  3. Handle login redirect on iOS

    Adam Cummings committed Aug 28, 2017
    Copy the full SHA
    866a52e View commit details

Commits on May 7, 2018

  1. Copy the full SHA
    95bb038 View commit details
4 changes: 2 additions & 2 deletions Native/TwitterKitAndroidWrapper/app/build.gradle
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ android {

dependencies {
provided fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.twitter.sdk.android:twitter-core:3.0.0'
compile 'com.twitter.sdk.android:tweet-composer:3.0.0'
compile 'com.twitter.sdk.android:twitter-core:3.1.1'
compile 'com.twitter.sdk.android:tweet-composer:3.1.1'
}

class UnityPlugin implements Plugin<Project> {
2 changes: 1 addition & 1 deletion Native/TwitterKitAndroidWrapper/app/gradle.properties
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@

# The to be released version. When releasing, drop -SNAPSHOT. After releasing, bump version
# number and add back -SNAPSHOT
version=3.0.0
version=3.1.1
version_code=1

pom_name=Twitter Unity Android SDK
Original file line number Diff line number Diff line change
@@ -19,5 +19,14 @@
package="com.twitter.sdk.android.unity">
<application>
<activity android:name="com.twitter.sdk.android.unity.LoginActivity"/>
<receiver
android:name="com.twitter.sdk.android.unity.TweetReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.TWEET_COMPOSE_CANCEL"/>
</intent-filter>
</receiver>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.twitter.sdk.android.unity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.twitter.sdk.android.tweetcomposer.TweetUploadService;

public class TweetReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null) {
if (TweetUploadService.UPLOAD_SUCCESS.equals(intent.getAction())) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
sendSuccessMessage(intentExtras.getLong(TweetUploadService.EXTRA_TWEET_ID));
}
} else if (TweetUploadService.UPLOAD_FAILURE.equals(intent.getAction())) {
sendFailureMessage();
} else if (TweetUploadService.TWEET_COMPOSE_CANCEL.equals(intent.getAction())) {
sendCancelMessage();
}
}
}

private void sendSuccessMessage(Long tweetId) {
final UnityMessage message = new UnityMessage.Builder()
.setMethod("TweetComplete")
.setData(Long.toString(tweetId))
.build();
message.send();
}

private void sendFailureMessage() {
final UnityMessage message = new UnityMessage.Builder()
.setMethod("TweetFailed")
.setData("")
.build();
message.send();
}

private void sendCancelMessage() {
final UnityMessage message = new UnityMessage.Builder()
.setMethod("TweetCancelled")
.build();
message.send();
}
}
3 changes: 2 additions & 1 deletion OWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
adamc
efrohnhoefer
jaiheel
jaiheel
rajularora
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
**Twitter will be discontinuing support for Twitter Kit on October 31, 2018. [Read the blog post here](https://blog.twitter.com/developer/en_us/topics/tools/2018/discontinuing-support-for-twitter-kit-sdk.html).**
___

# Twitter Kit for Unity

Twitter Kit for Unity provides cross-platform support (iOS & Android) for authorizing users and composing Tweets, allowing you to share great moments from your game with the world.

## Building
1. Download Twitter Kit frameworks.
```
./scripts/download_ios_frameworks.sh
./scripts/download_ios_frameworks.sh [version #] (e.g.: ./scripts/download_ios_frameworks.sh 3.1.0)
```
2. Build the Android wrapper.
```
6 changes: 5 additions & 1 deletion scripts/download_ios_frameworks.sh
Original file line number Diff line number Diff line change
@@ -13,10 +13,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ "$#" -ne 1 ]; then
echo "Usage: ./scripts/download_ios_frameworks.sh [version #] (e.g.: ./scripts/download_ios_frameworks.sh 3.1.0)" >&2
exit 1
fi

. $(dirname $0)/common.sh

TWITTER_KIT_IOS_URL="https://ton.twimg.com/syndication/twitterkit/ios/3.0.4/Twitter-Kit-iOS.zip"
TWITTER_KIT_IOS_URL="https://ton.twimg.com/syndication/twitterkit/ios/$1/Twitter-Kit-iOS.zip"
UNITY_IOS_PLUGIN_PATH=$UNITY_PACKAGE_ROOT/$UNITY_IOS_PLUGIN
TEMP_PATH="output.zip"
mkdir -p $UNITY_IOS_PLUGIN_PATH
2 changes: 1 addition & 1 deletion source/Assets/Plugins/iOS/TwitterKitIOSWrapper.h
Original file line number Diff line number Diff line change
@@ -16,6 +16,6 @@
#import "AppDelegateListener.h"
#include "RegisterMonoModules.h"

@interface TwitterUnityWrapper : NSObject <AppDelegateListener>
@interface TwitterUnityWrapper : NSObject <AppDelegateListener, TWTRComposerViewControllerDelegate>
+ (TwitterUnityWrapper *)sharedInstance;
@end
111 changes: 69 additions & 42 deletions source/Assets/Plugins/iOS/TwitterKitIOSWrapper.mm
Original file line number Diff line number Diff line change
@@ -15,42 +15,6 @@
#import <TwitterKit/TwitterKit.h>
#import "TwitterKitIOSWrapper.h"

static TwitterUnityWrapper *_instance = [TwitterUnityWrapper sharedInstance];

@implementation TwitterUnityWrapper

+ (TwitterUnityWrapper *)sharedInstance
{
if(_instance == nil) {
_instance = [[TwitterUnityWrapper alloc] init];
}

return _instance;
}

- (id)init
{
if(_instance != nil) {
return _instance;
}

if ((self = [super init])) {
_instance = self;
UnityRegisterAppDelegateListener(self);
}

return self;
}

- (void)onOpenURL:(NSNotification *)notification
{
[[Twitter sharedInstance] application:[UIApplication sharedApplication]
openURL:notification.userInfo[@"url"]
options:notification.userInfo[@"annotation"]];
}

@end

/**
* Constants for posting responses via messages to Unity.
*/
@@ -59,17 +23,20 @@ - (void)onOpenURL:(NSNotification *)notification
static const char * TWTRUnityAPIMethodLogInFailed = "LoginFailed";
static const char * TWTRUnityAPIMethodRequestEmailComplete = "RequestEmailComplete";
static const char * TWTRUnityAPIMethodRequestEmailFailed = "RequestEmailFailed";
static const char * TWTRUnityAPIMethodTweetComplete = "TweetComplete";
static const char * TWTRUnityAPIMethodTweetFailed = "TweetFailed";
static const char * TWTRUnityAPIMethodTweetCancelled = "TweetCancelled";

#pragma mark - String Helpers

static char * cStringCopy(const char *string)
{
if (string == NULL)
return NULL;

char *res = (char *)malloc(strlen(string) + 1);
strcpy(res, string);

return res;
}

@@ -87,7 +54,7 @@ - (void)onOpenURL:(NSNotification *)notification
if (!dictionary) {
return NULL;
}

NSData *serializedData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
NSString *serializedJSONString = [[NSString alloc] initWithData:serializedData encoding:NSUTF8StringEncoding];
return cStringCopy([serializedJSONString UTF8String]);
@@ -101,7 +68,7 @@ - (void)onOpenURL:(NSNotification *)notification
if (!session) {
return nil;
}

return @{ @"id": @(session.userID.longLongValue), @"auth_token": @{ @"token": session.authToken, @"secret": session.authTokenSecret }, @"user_name": session.userName };
}

@@ -110,6 +77,64 @@ - (void)onOpenURL:(NSNotification *)notification
return @{ @"code": @(error.code), @"message": error.localizedDescription };
}

static TwitterUnityWrapper *_instance = [TwitterUnityWrapper sharedInstance];

@implementation TwitterUnityWrapper

+ (TwitterUnityWrapper *)sharedInstance
{
if(_instance == nil) {
_instance = [[TwitterUnityWrapper alloc] init];
}

return _instance;
}

- (id)init
{
if(_instance != nil) {
return _instance;
}

if ((self = [super init])) {
_instance = self;
UnityRegisterAppDelegateListener(self);
}

return self;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
return [[Twitter sharedInstance] application:app openURL:url options:options];
}

- (void)onOpenURL:(NSNotification *)notification
{
[[Twitter sharedInstance] application:[UIApplication sharedApplication]
openURL:notification.userInfo[@"url"]
options:notification.userInfo[@"annotation"]];
}

- (void)composerDidCancel:(TWTRComposerViewController *)controller
{
UnitySendMessage(TWTRInternalGameObject, TWTRUnityAPIMethodTweetCancelled, "");
}

- (void)composerDidFail:(TWTRComposerViewController *)controller withError:(NSError *)error
{
NSDictionary *errorDictionary = NSDictionaryFromError(error);
char *serializedError = serializedJSONFromNSDictionary(errorDictionary);
UnitySendMessage(TWTRInternalGameObject, TWTRUnityAPIMethodTweetFailed, serializedError);
}

- (void)composerDidSucceed:(TWTRComposerViewController *)controller withTweet:(TWTRTweet *)tweet
{
char *cStringTweetId = cStringCopy([tweet.tweetID UTF8String]);
UnitySendMessage(TWTRInternalGameObject, TWTRUnityAPIMethodTweetComplete, cStringTweetId);
}

@end

__BEGIN_DECLS

#pragma mark - TwitterKit Unity Wrapper
@@ -130,8 +155,9 @@ void TwitterInit(const char *consumerKey, const char *consumerSecret)
*/
void TwitterLogIn()
{
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
if (session) {
UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
[[Twitter sharedInstance] logInWithViewController:rootViewController completion:^(TWTRSession *session, NSError *error) {
if (session) {
NSDictionary *sessionDictionary = NSDictionaryFromTWTRSession(session);
char *serializedSession = serializedJSONFromNSDictionary(sessionDictionary);
UnitySendMessage(TWTRInternalGameObject, TWTRUnityAPIMethodLogInComplete, serializedSession);
@@ -193,6 +219,7 @@ void TwitterCompose(const char *userID, const char *imageURI, const char *text,
}

TWTRComposerViewController *composerVC = [[TWTRComposerViewController alloc] initWithInitialText:[NSString stringWithFormat:@"%@%@", NSStringFromCString(text), hashtagsString] image:image videoURL:nil];
composerVC.delegate = TwitterUnityWrapper.sharedInstance;

[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:composerVC animated:YES completion:nil];
}
11 changes: 7 additions & 4 deletions source/Assets/Twitter/Demo/Scripts/TwitterDemo.cs
Original file line number Diff line number Diff line change
@@ -13,27 +13,30 @@ public void startLogin() {
// To set API key navigate to tools->Twitter Kit
Twitter.Init ();

Twitter.LogIn (LoginCompleteWithEmail, (ApiError error) => {
Twitter.LogIn (LoginCompleteWithCompose, (ApiError error) => {
UnityEngine.Debug.Log (error.message);
});
}

public void LoginCompleteWithEmail (TwitterSession session) {
// To get the user's email address you must have "Request email addresses from users" enabled on https://apps.twitter.com/ (Permissions -> Additional Permissions)
UnityEngine.Debug.Log ("LoginCompleteWithEmail()");
Twitter.RequestEmail (session, RequestEmailComplete, (ApiError error) => { UnityEngine.Debug.Log (error.message); });
}

public void RequestEmailComplete (string email) {
UnityEngine.Debug.Log ("email=" + email);

LoginCompleteWithCompose ( Twitter.Session );
}

public void LoginCompleteWithCompose(TwitterSession session) {
Application.CaptureScreenshot("Screenshot.png");
UnityEngine.Debug.Log ("Screenshot location=" + Application.persistentDataPath + "/Screenshot.png");
string imageUri = "file://" + Application.persistentDataPath + "/Screenshot.png";

Twitter.Compose (session, imageUri, "Welcome to", new string[]{"#TwitterKitUnity"});
Twitter.Compose (session, imageUri, "Welcome to", new string[]{"#TwitterKitUnity"},
(string tweetId) => { UnityEngine.Debug.Log ("Tweet Success, tweetId=" + tweetId); },
(ApiError error) => { UnityEngine.Debug.Log ("Tweet Failed " + error.message); },
() => { Debug.Log ("Compose cancelled"); }
);
}
}
12 changes: 10 additions & 2 deletions source/Assets/Twitter/Scripts/Twitter.cs
Original file line number Diff line number Diff line change
@@ -68,13 +68,15 @@ public static void LogIn (Action<TwitterSession> successCallback = null, Action<
twitterGameObject.GetComponent<TwitterComponent> ().loginFailureAction = failureCallback;
twitter.LogIn ();
}

/// <summary>
/// Logout of current session
/// </summary>
public static void LogOut ()
{
twitter.LogOut ();
}

/// <summary>
/// Returns the active session.
/// </summary>
@@ -92,17 +94,23 @@ public static void RequestEmail (TwitterSession session, Action<string> successC
twitterGameObject.GetComponent<TwitterComponent> ().emailFailureAction = failureCallback;
twitter.RequestEmail (session);
}

/// <summary>
/// Show Twitter composer
/// <param name="session">User’s session from Login</param>
/// <param name="imageUri">uri of image to include in tweet</param>
/// <param name="text">text to tweet to pre-fill</param>
/// <param name="hashtags">hashtags to pre-fill</param>
/// <param name="successCallback">Callback to call on success</param>
/// <param name="failureCallback">Callback to call on failure</param>
/// <param name="cancelCallback">Callback to call on cancel</param>
/// </summary>
public static void Compose (TwitterSession session, String imageUri, String text, string[] hashtags = null)
public static void Compose (TwitterSession session, String imageUri, String text, string[] hashtags = null, Action<string> successCallback = null, Action<ApiError> failureCallback = null, Action cancelCallback = null)
{
twitterGameObject.GetComponent<TwitterComponent> ().tweetSuccessAction = successCallback;
twitterGameObject.GetComponent<TwitterComponent> ().tweetFailureAction = failureCallback;
twitterGameObject.GetComponent<TwitterComponent> ().tweetCancelAction = cancelCallback;
twitter.Compose (session, imageUri, text, hashtags);
}
}

}
Loading