c# - Linq2Twitter Single User Authorisation Null Value Exception -
i've been developing internal asp.net web forms application our business , 1 of requirements display our twitter feed on our portal home page users.
for i've decided best use linqtotwitter single user authorisation statuses without them having authenticate own accounts.
my main problem @ minute when use auth object twittercontext, returns error on twittercontext saying
value cannot null
on every internal context object.
i've gone through our twitter application settings @ http://dev.twitter.com , have our correct consumer key/token , access key/token. permission application set read-only. there no callback url specified on http://dev.twitter.com website on our internal system (so wouldn't able anyway). going wrong? need forward ports , allow callback through our development machines?
here's code prudence. far can see, there nothing wrong it. know set .firstordefault
, seeing whether getting (which isn't).
thanks can give! :)
private async task gettweets() { var auth = new singleuserauthorizer { credentialstore = new singleuserinmemorycredentialstore { consumerkey = configurationmanager.appsettings["consumerkey"], consumersecret = configurationmanager.appsettings["consumersecret"], accesstoken = configurationmanager.appsettings["accesstoken"], accesstokensecret = configurationmanager.appsettings["accesstokensecret"], } }; try { using (twittercontext twittercontext = new twittercontext(auth)) { var searchresponse = await (from c in twittercontext.status c.type == statustype.user && c.screenname == "my_screenname" select c).tolistasync(); tb_home_news.text = searchresponse.firstordefault().text; } } catch (exception ex) { tb_home_news.text = ex.message; } }
if you're creating web app, need add url twitter app page. isn't used callback, might avoid 401's in future if you're using aspnetauthorizer.
it looks have nullreferenceexception somewhere. ex.tostring() say?
double check credentialstore after initialization make sure 4 credentials populated. accesstoken , accesstokensecret come twitter app page.
does searchresponse contain values? calling firstordefault on empty collection return null.
Comments
Post a Comment