I'm using Autho0 to authenticate users of my app. I am trying to send tweets via Twitter4J (the Monodroid wrapper from Xamarin). When I attempt to send the tweet I get the "Received authentication challenge is null" exception. Here's the code:
using System;
using System.Threading;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Auth0.SDK;
using Newtonsoft.Json.Linq;
using Twitter4j;
using Twitter4j.Conf;
namespace MyNamespace
{
[Activity (Label = "App", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
Auth0User _user = null;
protected async override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
var auth0 = new Auth0Client(
"URL",
"KEY");
_user = await auth0.LoginAsync(this);
if (_user != null) {
var name = (string)_user.Profile["name"];
var provider = (string)_user.Profile ["identities"] [0] ["provider"];
var accessToken = (string)_user.Profile ["identities"] [0] ["access_token"];
var accessTokenSecret = (string)_user.Profile ["identities"] [0] ["access_token_secret"];
if (provider == "twitter") {
ConfigurationBuilder config = new ConfigurationBuilder();
config.SetOAuthConsumerKey("CONSUMERKEY");
config.SetOAuthConsumerSecret("CONSUMERSECRET");
config.SetOAuthAccessToken(accessToken);
config.SetOAuthAccessTokenSecret(accessTokenSecret);
config.SetUser(name);
var factory = new Twitter4j.TwitterFactory (config.Build());
//factory.Instance.
var twitter = factory.Instance;
ThreadPool.QueueUserWorkItem(state =>
{
try
{
twitter.UpdateStatus("The first tweet from our app!");
}
catch (Java.Lang.Exception ex)
{
Console.WriteLine(ex);
}
});
}
} else {
System.Diagnostics.Process.GetCurrentProcess ().CloseMainWindow ();
}
}
}
}
0 comments:
Post a Comment