- Home /
Program received signal: “SIGABRT”
hi,
i am using the lets tweet plugin to implement twitter posting into my game
the plugin seem to work fine in the editor bit it gives me an error Program received signal: “SIGABRT” when i run it on the device.
Demo.cs
using UnityEngine;
using System.Collections;
public class Demo : MonoBehaviour
{
public float USER_LOG_IN_X;
public float USER_LOG_IN_Y;
public float USER_LOG_IN_WIDTH;
public float USER_LOG_IN_HEIGHT;
public float PIN_INPUT_X;
public float PIN_INPUT_Y;
public float PIN_INPUT_WIDTH;
public float PIN_INPUT_HEIGHT;
public float PIN_ENTER_X;
public float PIN_ENTER_Y;
public float PIN_ENTER_WIDTH;
public float PIN_ENTER_HEIGHT;
public float TWEET_INPUT_X;
public float TWEET_INPUT_Y;
public float TWEET_INPUT_WIDTH;
public float TWEET_INPUT_HEIGHT;
public float POST_TWEET_X;
public float POST_TWEET_Y;
public float POST_TWEET_WIDTH;
public float POST_TWEET_HEIGHT;
// You need to register your game or application in Twitter to get cosumer key and secret.
// Go to this page for registration: http://dev.twitter.com/apps/new
public string CONSUMER_KEY;
public string CONSUMER_SECRET;
// You need to save access token and secret for later use.
// You can keep using them whenever you need to access the user's Twitter account.
// They will be always valid until the user revokes the access to your application.
const string PLAYER_PREFS_TWITTER_USER_ID = "TwitterUserID";
const string PLAYER_PREFS_TWITTER_USER_SCREEN_NAME = "TwitterUserScreenName";
const string PLAYER_PREFS_TWITTER_USER_TOKEN = "TwitterUserToken";
const string PLAYER_PREFS_TWITTER_USER_TOKEN_SECRET = "TwitterUserTokenSecret";
Twitter.RequestTokenResponse m_RequestTokenResponse;
Twitter.AccessTokenResponse m_AccessTokenResponse;
string m_PIN = "Please enter your PIN here.";
string m_Tweet = "Please enter your tweet here.";
// Use this for initialization
void Start()
{
LoadTwitterUserInfo();
}
// Update is called once per frame
void Update()
{
}
// GUI
void OnGUI()
{
// LogIn/Register Button
Rect rect = new Rect(Screen.width * USER_LOG_IN_X,
Screen.height * USER_LOG_IN_Y,
Screen.width * USER_LOG_IN_WIDTH,
Screen.height * USER_LOG_IN_HEIGHT);
if (string.IsNullOrEmpty(CONSUMER_KEY) || string.IsNullOrEmpty(CONSUMER_SECRET))
{
string text = "You need to register your game or application first.\n Click this button, register and fill CONSUMER_KEY and CONSUMER_SECRET of Demo game object.";
if (GUI.Button(rect, text))
{
Application.OpenURL("http://dev.twitter.com/apps/new");
}
}
else
{
string text = string.Empty;
if (!string.IsNullOrEmpty(m_AccessTokenResponse.ScreenName))
{
text = m_AccessTokenResponse.ScreenName + "\nClick to register with a different Twitter account";
}
else
{
text = "You need to register your game or application first.";
}
if (GUI.Button(rect, text))
{
StartCoroutine(Twitter.API.GetRequestToken(CONSUMER_KEY, CONSUMER_SECRET,
new Twitter.RequestTokenCallback(this.OnRequestTokenCallback)));
}
}
// PIN Input
rect.x = Screen.width * PIN_INPUT_X;
rect.y = Screen.height * PIN_INPUT_Y;
rect.width = Screen.width * PIN_INPUT_WIDTH;
rect.height = Screen.height * PIN_INPUT_HEIGHT;
m_PIN = GUI.TextField(rect, m_PIN);
// PIN Enter Button
rect.x = Screen.width * PIN_ENTER_X;
rect.y = Screen.height * PIN_ENTER_Y;
rect.width = Screen.width * PIN_ENTER_WIDTH;
rect.height = Screen.height * PIN_ENTER_HEIGHT;
if (GUI.Button(rect, "Enter PIN"))
{
StartCoroutine(Twitter.API.GetAccessToken(CONSUMER_KEY, CONSUMER_SECRET, m_RequestTokenResponse.Token, m_PIN,
new Twitter.AccessTokenCallback(this.OnAccessTokenCallback)));
}
// Tweet Input
rect.x = Screen.width * TWEET_INPUT_X;
rect.y = Screen.height * TWEET_INPUT_Y;
rect.width = Screen.width * TWEET_INPUT_WIDTH;
rect.height = Screen.height * TWEET_INPUT_HEIGHT;
m_Tweet = GUI.TextField(rect, m_Tweet);
// Post Tweet Button
rect.x = Screen.width * POST_TWEET_X;
rect.y = Screen.height * POST_TWEET_Y;
rect.width = Screen.width * POST_TWEET_WIDTH;
rect.height = Screen.height * POST_TWEET_HEIGHT;
if (GUI.Button(rect, "Post Tweet"))
{
StartCoroutine(Twitter.API.PostTweet(m_Tweet, CONSUMER_KEY, CONSUMER_SECRET, m_AccessTokenResponse,
new Twitter.PostTweetCallback(this.OnPostTweet)));
}
}
void LoadTwitterUserInfo()
{
m_AccessTokenResponse = new Twitter.AccessTokenResponse();
m_AccessTokenResponse.UserId = PlayerPrefs.GetString(PLAYER_PREFS_TWITTER_USER_ID);
m_AccessTokenResponse.ScreenName = PlayerPrefs.GetString(PLAYER_PREFS_TWITTER_USER_SCREEN_NAME);
m_AccessTokenResponse.Token = PlayerPrefs.GetString(PLAYER_PREFS_TWITTER_USER_TOKEN);
m_AccessTokenResponse.TokenSecret = PlayerPrefs.GetString(PLAYER_PREFS_TWITTER_USER_TOKEN_SECRET);
if (!string.IsNullOrEmpty(m_AccessTokenResponse.Token) &&
!string.IsNullOrEmpty(m_AccessTokenResponse.ScreenName) &&
!string.IsNullOrEmpty(m_AccessTokenResponse.Token) &&
!string.IsNullOrEmpty(m_AccessTokenResponse.TokenSecret))
{
string log = "LoadTwitterUserInfo - succeeded";
log += "\n UserId : " + m_AccessTokenResponse.UserId;
log += "\n ScreenName : " + m_AccessTokenResponse.ScreenName;
log += "\n Token : " + m_AccessTokenResponse.Token;
log += "\n TokenSecret : " + m_AccessTokenResponse.TokenSecret;
print(log);
}
}
void OnRequestTokenCallback(bool success, Twitter.RequestTokenResponse response)
{
if (success)
{
string log = "OnRequestTokenCallback - succeeded";
log += "\n Token : " + response.Token;
log += "\n TokenSecret : " + response.TokenSecret;
print(log);
m_RequestTokenResponse = response;
Twitter.API.OpenAuthorizationPage(response.Token);
}
else
{
print("OnRequestTokenCallback - failed.");
}
}
void OnAccessTokenCallback(bool success, Twitter.AccessTokenResponse response)
{
if (success)
{
string log = "OnAccessTokenCallback - succeeded";
log += "\n UserId : " + response.UserId;
log += "\n ScreenName : " + response.ScreenName;
log += "\n Token : " + response.Token;
log += "\n TokenSecret : " + response.TokenSecret;
print(log);
m_AccessTokenResponse = response;
PlayerPrefs.SetString(PLAYER_PREFS_TWITTER_USER_ID, response.UserId);
PlayerPrefs.SetString(PLAYER_PREFS_TWITTER_USER_SCREEN_NAME, response.ScreenName);
PlayerPrefs.SetString(PLAYER_PREFS_TWITTER_USER_TOKEN, response.Token);
PlayerPrefs.SetString(PLAYER_PREFS_TWITTER_USER_TOKEN_SECRET, response.TokenSecret);
}
else
{
print("OnAccessTokenCallback - failed.");
}
}
void OnPostTweet(bool success)
{
print("OnPostTweet - " + (success ? "succedded." : "failed."));
}
}
Twitter.cs
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Linq;
using System.Security.Cryptography;
using System.Reflection;
using UnityEngine;
namespace Twitter
{
public class RequestTokenResponse
{
public string Token { get; set; }
public string TokenSecret { get; set; }
}
public class AccessTokenResponse
{
public string Token { get; set; }
public string TokenSecret { get; set; }
public string UserId { get; set; }
public string ScreenName { get; set; }
}
public delegate void RequestTokenCallback(bool success, RequestTokenResponse response);
public delegate void AccessTokenCallback(bool success, AccessTokenResponse response);
public delegate void PostTweetCallback(bool success);
public class API
{
#region OAuth Token Methods
// 1. Get Request-Token From Twitter
// 2. Get PIN from User
// 3. Get Access-Token from Twitter
// 4. Use Accss-Token for APIs requriring OAuth
// Accss-Token will be always valid until the user revokes the access to your application.
// Twitter APIs for OAuth process
private static readonly string RequestTokenURL = "https://api.twitter.com/oauth/request_token?oauth_callback=oob";
private static readonly string AuthorizationURL = "http://api.twitter.com/oauth/authorize?oauth_token={0}";
private static readonly string AccessTokenURL = "https://api.twitter.com/oauth/access_token";
public static IEnumerator GetRequestToken(string consumerKey, string consumerSecret, RequestTokenCallback callback)
{
WWW web = WWWRequestToken(consumerKey, consumerSecret);
yield return web;
if (!string.IsNullOrEmpty(web.error))
{
Debug.Log(string.Format("GetRequestToken - failed. error : {0}", web.error));
callback(false, null);
}
else
{
RequestTokenResponse response = new RequestTokenResponse
{
Token = Regex.Match(web.text, @"oauth_token=([^&]+)").Groups[1].Value,
TokenSecret = Regex.Match(web.text, @"oauth_token_secret=([^&]+)").Groups[1].Value,
};
if (!string.IsNullOrEmpty(response.Token) &&
!string.IsNullOrEmpty(response.TokenSecret))
{
callback(true, response);
}
else
{
Debug.Log(string.Format("GetRequestToken - failed. response : {0}", web.text));
callback(false, null);
}
}
}
public static void OpenAuthorizationPage(string requestToken)
{
Application.OpenURL(string.Format(AuthorizationURL, requestToken));
}
public static IEnumerator GetAccessToken(string consumerKey, string consumerSecret, string requestToken, string pin, AccessTokenCallback callback)
{
WWW web = WWWAccessToken(consumerKey, consumerSecret, requestToken, pin);
yield return web;
if (!string.IsNullOrEmpty(web.error))
{
Debug.Log(string.Format("GetAccessToken - failed. error : {0}", web.error));
callback(false, null);
}
else
{
AccessTokenResponse response = new AccessTokenResponse
{
Token = Regex.Match(web.text, @"oauth_token=([^&]+)").Groups[1].Value,
TokenSecret = Regex.Match(web.text, @"oauth_token_secret=([^&]+)").Groups[1].Value,
UserId = Regex.Match(web.text, @"user_id=([^&]+)").Groups[1].Value,
ScreenName = Regex.Match(web.text, @"screen_name=([^&]+)").Groups[1].Value
};
if (!string.IsNullOrEmpty(response.Token) &&
!string.IsNullOrEmpty(response.TokenSecret) &&
!string.IsNullOrEmpty(response.UserId) &&
!string.IsNullOrEmpty(response.ScreenName))
{
callback(true, response);
}
else
{
Debug.Log(string.Format("GetAccessToken - failed. response : {0}", web.text));
callback(false, null);
}
}
}
private static WWW WWWRequestToken(string consumerKey, string consumerSecret)
{
// Need to fill body since Unity doesn't like an empty request body.
byte[] dummmy = new byte[1];
dummmy[0] = 0;
// HTTP header
Hashtable headers = new Hashtable();
Dictionary<string, string> parameters = new Dictionary<string, string>();
AddDefaultOAuthParams(parameters, consumerKey, consumerSecret);
parameters.Add("oauth_callback", "oob");
headers["Authorization"] = GetFinalOAuthHeader("POST", RequestTokenURL, parameters);
return new WWW(RequestTokenURL, dummmy, headers);
}
private static WWW WWWAccessToken(string consumerKey, string consumerSecret, string requestToken, string pin)
{
// Need to fill body since Unity doesn't like an empty request body.
byte[] dummmy = new byte[1];
dummmy[0] = 0;
// HTTP header
Hashtable headers = new Hashtable();
Dictionary<string, string> parameters = new Dictionary<string, string>();
AddDefaultOAuthParams(parameters, consumerKey, consumerSecret);
parameters.Add("oauth_token", requestToken);
parameters.Add("oauth_verifier", pin);
headers["Authorization"] = GetFinalOAuthHeader("POST", AccessTokenURL, parameters);
return new WWW(AccessTokenURL, dummmy, headers);
}
private static string GetHeaderWithAccessToken(string httpRequestType, string apiURL, string consumerKey, string consumerSecret, AccessTokenResponse response, Dictionary<string, string> parameters)
{
AddDefaultOAuthParams(parameters, consumerKey, consumerSecret);
parameters.Add("oauth_token", response.Token);
parameters.Add("oauth_token_secret", response.TokenSecret);
return GetFinalOAuthHeader(httpRequestType, apiURL, parameters);
}
#endregion
#region Twitter API Methods
private static readonly string PostTweetURL = "http://api.twitter.com/1/statuses/update.xml?status={0}";
public static IEnumerator PostTweet(string text, string consumerKey, string consumerSecret, AccessTokenResponse response, PostTweetCallback callback)
{
if (string.IsNullOrEmpty(text) || text.Length > 140)
{
Debug.Log(string.Format("PostTweet - text[{0}] is empty or too long.", text));
callback(false);
}
else
{
string url = string.Format(PostTweetURL, UrlEncode(text));
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("status", text);
// Need to fill body since Unity doesn't like an empty request body.
byte[] dummmy = new byte[1];
dummmy[0] = 0;
// HTTP header
Hashtable headers = new Hashtable();
headers["Authorization"] = GetHeaderWithAccessToken("POST", url, consumerKey, consumerSecret, response, parameters);
WWW web = new WWW(url, dummmy, headers);
yield return web;
if (!string.IsNullOrEmpty(web.error))
{
Debug.Log(string.Format("PostTweet - failed. {0}", web.error));
callback(false);
}
else
{
string error = Regex.Match(web.text, @"<error>([^&]+)</error>").Groups[1].Value;
if (!string.IsNullOrEmpty(error))
{
Debug.Log(string.Format("PostTweet - failed. {0}", error));
callback(false);
}
else
{
callback(true);
}
}
}
}
#endregion
#region OAuth Help Methods
// The below help methods are modified from "WebRequestBuilder.cs" in Twitterizer(http://www.twitterizer.net/).
// Here is its license.
//-----------------------------------------------------------------------
// <copyright file="WebRequestBuilder.cs" company="Patrick 'Ricky' Smith">
// This file is part of the Twitterizer library (http://www.twitterizer.net/)
//
// Copyright (c) 2010, Patrick "Ricky" Smith (ricky@digitally-born.com)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
// - Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// - Neither the name of the Twitterizer nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// </copyright>
// <author>Ricky Smith</author>
// <summary>Provides the means of preparing and executing Anonymous and OAuth signed web requests.</summary>
//-----------------------------------------------------------------------
private static readonly string[] OAuthParametersToIncludeInHeader = new[]
{
"oauth_version",
"oauth_nonce",
"oauth_timestamp",
"oauth_signature_method",
"oauth_consumer_key",
"oauth_token",
"oauth_verifier"
// Leave signature omitted from the list, it is added manually
// "oauth_signature",
};
private static readonly string[] SecretParameters = new[]
{
"oauth_consumer_secret",
"oauth_token_secret",
"oauth_signature"
};
private static void AddDefaultOAuthParams(Dictionary<string, string> parameters, string consumerKey, string consumerSecret)
{
parameters.Add("oauth_version", "1.0");
parameters.Add("oauth_nonce", GenerateNonce());
parameters.Add("oauth_timestamp", GenerateTimeStamp());
parameters.Add("oauth_signature_method", "HMAC-SHA1");
parameters.Add("oauth_consumer_key", consumerKey);
parameters.Add("oauth_consumer_secret", consumerSecret);
}
private static string GetFinalOAuthHeader(string HTTPRequestType, string URL, Dictionary<string, string> parameters)
{
// Add the signature to the oauth parameters
string signature = GenerateSignature(HTTPRequestType, URL, parameters);
parameters.Add("oauth_signature", signature);
StringBuilder authHeaderBuilder = new StringBuilder();
authHeaderBuilder.AppendFormat("OAuth realm=\"{0}\"", "Twitter API");
var sortedParameters = from p in parameters
where OAuthParametersToIncludeInHeader.Contains(p.Key)
orderby p.Key, UrlEncode(p.Value)
select p;
foreach (var item in sortedParameters)
{
authHeaderBuilder.AppendFormat(",{0}=\"{1}\"", UrlEncode(item.Key), UrlEncode(item.Value));
}
authHeaderBuilder.AppendFormat(",oauth_signature=\"{0}\"", UrlEncode(parameters["oauth_signature"]));
return authHeaderBuilder.ToString();
}
private static string GenerateSignature(string httpMethod, string url, Dictionary<string, string> parameters)
{
var nonSecretParameters = (from p in parameters
where !SecretParameters.Contains(p.Key)
select p);
// Create the base string. This is the string that will be hashed for the signature.
string signatureBaseString = string.Format(CultureInfo.InvariantCulture,
"{0}&{1}&{2}",
httpMethod,
UrlEncode(NormalizeUrl(new Uri(url))),
UrlEncode(nonSecretParameters));
// Create our hash key (you might say this is a password)
string key = string.Format(CultureInfo.InvariantCulture,
"{0}&{1}",
UrlEncode(parameters["oauth_consumer_secret"]),
parameters.ContainsKey("oauth_token_secret") ? UrlEncode(parameters["oauth_token_secret"]) : string.Empty);
// Generate the hash
HMACSHA1 hmacsha1 = new HMACSHA1(Encoding.ASCII.GetBytes(key));
byte[] signatureBytes = hmacsha1.ComputeHash(Encoding.ASCII.GetBytes(signatureBaseString));
return Convert.ToBase64String(signatureBytes);
}
private static string GenerateTimeStamp()
{
// Default implementation of UNIX time of the current UTC time
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds, CultureInfo.CurrentCulture).ToString(CultureInfo.CurrentCulture);
}
private static string GenerateNonce()
{
// Just a simple implementation of a random number between 123400 and 9999999
return new System.Random().Next(123400, int.MaxValue).ToString("X", CultureInfo.InvariantCulture);
}
private static string NormalizeUrl(Uri url)
{
string normalizedUrl = string.Format(CultureInfo.InvariantCulture, "{0}://{1}", url.Scheme, url.Host);
if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443)))
{
normalizedUrl += ":" + url.Port;
}
normalizedUrl += url.AbsolutePath;
return normalizedUrl;
}
private static string UrlEncode(string value)
{
if (string.IsNullOrEmpty(value))
{
return string.Empty;
}
value = Uri.EscapeDataString(value);
// UrlEncode escapes with lowercase characters (e.g. %2f) but oAuth needs %2F
value = Regex.Replace(value, "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper());
// these characters are not escaped by UrlEncode() but needed to be escaped
value = value
.Replace("(", "%28")
.Replace(")", "%29")
.Replace("$", "%24")
.Replace("!", "%21")
.Replace("*", "%2A")
.Replace("'", "%27");
// these characters are escaped by UrlEncode() but will fail if unescaped!
value = value.Replace("%7E", "~");
return value;
}
private static string UrlEncode(IEnumerable<KeyValuePair<string, string>> parameters)
{
StringBuilder parameterString = new StringBuilder();
var paramsSorted = from p in parameters
orderby p.Key, p.Value
select p;
foreach (var item in paramsSorted)
{
if (parameterString.Length > 0)
{
parameterString.Append("&");
}
parameterString.Append(
string.Format(
CultureInfo.InvariantCulture,
"{0}={1}",
UrlEncode(item.Key),
UrlEncode(item.Value)));
}
return UrlEncode(parameterString.ToString());
}
#endregion
}
}
These are the two scripts used the moment i press the "You need to register your application" button****. the game crashes.i searched for it in the google docs and found out that this error generally occurs whenever there is a null reference,but i cannot figure out where can anyone please help me out with this.
the build setting are
Api compatibility level : .Net 2.0 subset Stripping level : micro mscorlib
Your answer
Follow this Question
Related Questions
NullReferenceException on empty project because of ScriptCompilerBase 0 Answers
Vector3.Distance giving me NullReferenceException every time 1 Answer
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Problem for moving an object with a button 0 Answers
Object reference not set to an instance of an object 1 Answer