I have been using the older version of Skybrud.Social to fetch twitter feeds on the site, which was working ok.
After I installed the update 1.02 I get an exception for line 87 :
Compiler Error Message: CS0246: The type or namespace name 'TwitterHashTagEntitity' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 85: string after = text.Substring(entity.EndIndex);
Line 86:
Line 87: if (entity is TwitterHashTagEntitity) {
Line 88: TwitterHashTagEntitity tag = (TwitterHashTagEntitity) entity;
Line 89: text = before + "#" + tag.Text + "" + after;
The new release is build against Skybrud.Social 0.9.4.1, while the previous release was build against Skybrud.Social 0.9.1.1. But as far as I remember, there shouldn't be any breaking changes for the TwitterHashTagEntity class, but I'll look into that. For reference, you can see the history of the class/file here:
Anyways, if you add using Skybrud.Social.Twitter.Entities; to the top of your file, it should work.
Just to be sure, if you check the properties of the Skybrud.Social.dll, what version does it say? And how did you install/update the package? NuGet or via the Umbraco Package?
I have done a quick check. I noticed I was happily running the version 1.0 with U7.1.8.
The twitter oauth was giving a weird once-in-blue-moon authentication exception, but it normally turned ok after refreshing the page few times - and didnt happen again. So I accepted this is a twitter related delay of some sort and lived with it.
When I see the updated package, tried installing 1.02 on to 1.0.
I encountered the error above when I uploaded 1.0.2, after then I uninstall the package.
Then installed 1.01 version. The same exception was thrown.
After which i uninstalled 1.01 and installed back the archive 1.0 version.
Then it started working again as normal with 1.0, the exception thrown is exactly the same on 1.02 and 1.01.
Now its running on 1.0
I have tried it on two system, so I believe the steps can be replicated (users on 1.0 upgrading to 1.02 (or 1.01) ).
Dll properties from uninstalling 1.01 and back to 1.0: (i.e. version that doesnt throw exception)
It seems the DLL was the same for 1.01, as the previous sshot of the same dll properties looks same:
dll properties from 1.01 package install:
I have checked the partial where the twitter content is fetched and it already has the reference Skybrud.Social.Twitter.Entities
I'm not sure that I understand - did you experience two separate errors, or just the one that you posted in your first post?
Regarding the error you posted earlier, version 1.0.1 had some breaking changes due to a newer version of Skybrud.Social, so the fix should just be to update your own code a bit. If you can post some more of your code here, I'd be happy to help updating the code to use the newer version ;)
Anyways, if you don't need any of the new logic in Skybrud.Social, it should be fine to stick with Skybrud.Social for Umbraco 7 v1.0.0 (although v1.0.2 fixes an issue if you're using compositions).
The same error on both 1.01 and 1.02, not two separate errors.
This is the partial code, added try-catch when i get on-and-off twitter authentication errors and couldnt figure out why - repetitive refresh of page solved the issue so i'll let it be.
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@using Skybrud.Social.Twitter
@using Skybrud.Social.Twitter.Objects
@using Skybrud.Social.Umbraco.Twitter.PropertyEditors.OAuth
@using Skybrud.Social.Twitter.Entities
@functions {
public string getTheRelativeTime(System.DateTime COMPdatetime){
var ts = new TimeSpan(DateTime.UtcNow.Ticks - COMPdatetime.Ticks);
double delta = Math.Abs(ts.TotalSeconds);
const int SECOND = 1;
const int MINUTE = 60 * SECOND;
const int HOUR = 60 * MINUTE;
const int DAY = 24 * HOUR;
const int MONTH = 30 * DAY;
if (delta < 0)
{
return "not yet";
}
if (delta < 1 * MINUTE)
{
return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
}
if (delta < 2 * MINUTE)
{
return "a minute ago";
}
if (delta < 45 * MINUTE)
{
return ts.Minutes + " minutes ago";
}
if (delta < 90 * MINUTE)
{
return "an hour ago";
}
if (delta < 24 * HOUR)
{
return ts.Hours + " hours ago";
}
if (delta < 48 * HOUR)
{
return "yesterday";
}
if (delta < 30 * DAY)
{
return ts.Days + " days ago";
}
if (delta < 12 * MONTH)
{
int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
return months <= 1 ? "one month ago" : months + " months ago";
}
else
{
int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));
return years <= 1 ? "one year ago" : years + " years ago";
}
}
private string FormatStatusMessageText(TwitterStatusMessage tweet) {
// Normally we should be able to call tweet.Entities.GetAllReversed() but that method
// will throw an exception if the array of media entities is NULL (which it is if there
// are no media attached to the tweet).
List<TwitterBaseEntity> entities = new List<TwitterBaseEntity>();
entities.AddRange(tweet.Entities.HashTags);
entities.AddRange(tweet.Entities.Urls);
entities.AddRange(tweet.Entities.Mentions);
if (tweet.Entities.Media != null) entities.AddRange(tweet.Entities.Media);
// Get the original text
string text = tweet.Text;
// We read the entities from back to front so we don't break the indices while manipulating the string
foreach (var entity in entities.OrderByDescending(x => x.StartIndex)) {
string before = text.Substring(0, entity.StartIndex);
string current = text.Substring(entity.StartIndex, entity.EndIndex - entity.StartIndex);
string after = text.Substring(entity.EndIndex);
if (entity is TwitterHashTagEntitity) {
TwitterHashTagEntitity tag = (TwitterHashTagEntitity) entity;
text = before + "<a target=\"_blank\" href=\"https://twitter.com/hashtag/" + tag.Text + "?src=hash\">#" + tag.Text + "</a>" + after;
} else if (entity is TwitterUrlEntitity) {
TwitterUrlEntitity url = (TwitterUrlEntitity) entity;
text = before + "<a target=\"_blank\" href=\"" + url.Url + "\">" + url.DisplayUrl + "</a>" + after;
} else if (entity is TwitterMentionEntity) {
TwitterMentionEntity mention = (TwitterMentionEntity) entity;
text = before + "<a target=\"_blank\" href=\"https://twitter.com/" + mention.ScreenName + "\">@" + mention.ScreenName + "</a>" + after;
} else if (entity is TwitterMediaEntity) {
TwitterMediaEntity media = (TwitterMediaEntity) entity;
text = before + "<a target=\"_blank\" href=\"" + media.MediaUrl + "\">" + current + "</a>" + after;
}
}
return text;
}
}
@{
try {
// Get the OAuth information stored in the property
TwitterOAuthData twitter = Model.GetPropertyValue("COMPtwitter") as TwitterOAuthData;
// Check whether the OAuth data is valid
if (twitter != null && twitter.IsValid) {
// Gets an instance of TwitterService based on the OAuth data
TwitterService service = twitter.GetService();
// Get information about the authenticated user
TwitterUser user = service.Users.GetUser(twitter.Id);
// Get recent status messages (tweets) from the authenticated user
TwitterTimeline recent = service.Statuses.UserTimeline(user.Id);
<div class="ui--title ui--animation ui--title-bordered text-left">
<div class="ui--title-holder">
<h3 class="ui--title-text">Latest <strong>Tweets</strong></h3>
<div class="ui--title-borders ui--title-border-left"></div>
<div class="ui--title-borders ui--title-border-right"></div>
</div>
</div>
<div class="ui--carousel clearfix" data-options="{"effect":"slide","auto_rotate":"1","animation_loop":"FALSE","arrows":true,"rotate_time":10000,"animate":true}">
<div class="slides twitty">
@foreach (TwitterStatusMessage status in recent.StatusMessages) {
<div class="ui-row row">
<div class="ui-column span12">
<div class="ui--carousel-item ui--twitter-style-default ui--twitter-timeline-wrap ui--animation clearfix">
<div class="ui--twitter-timeline clearfix">
<div class="ui--twitter-timeline-content ui--box ui--gradient ui--gradient-grey auto-format clearfix">
<p>@Html.Raw(FormatStatusMessageText(status))</p>
<div class="ui--twitter-timeline-arrow"><i class="fontawesome-caret-down"></i></div>
</div>
<div class="ui--twitter-timeline-brand clearfix ui--animation" data-fx="fx--fadein-btt">
<div class="ui--twitter-timeline-image">
<div class="ui--twitter-timeline-image-position">
<a href="#" target="_blank">
<img src="/images/twitter.png" alt="" />
</a>
</div>
</div>
<div class="ui--twitter-timeline-user">
<strong class="name">Twitter</strong>
<small class="cap timestamp">
<a href="https://twitter.com/twitter/status/@status.Id" class="muted" target="_blank">@getTheRelativeTime(status.CreatedAt)</a> </small>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
}
</div><!--end twitter slides-->
</div> <!--twitter feed-->
}
} catch (Exception ex) {}
}
It seem the < pre > is not working with html, which tag i should use to post so all code with html will be visible here? [EDITED: paste code, select and Ctrl+K ]
Okay, I'll look into that ;) Did you install the NuGet package or the Umbraco package?
Code blocks on Our should be indented with four spaces. You can use the Code Sample button over the editor for this, or just insert your code, select it and press CTRL + K.
I had another look at your partial. The problem with the entity classes was that I initially had spelled the class names wrong - eg. the class for a hashtag entity was named TwitterHashTagEntitity in earlier versions, but was later renamed to TwitterHashTagEntity.
Also in earlier versions, a call to the Twitter API (eg. GetUser method) would return a object or array representing the response body, while in newer versions, the same method will return an object representing the entire response. I have updated this in your partial as well.
Exception Error after installing 1.02 update
I have been using the older version of Skybrud.Social to fetch twitter feeds on the site, which was working ok.
After I installed the update 1.02 I get an exception for line 87 :
Hi keilo,
The new release is build against Skybrud.Social 0.9.4.1, while the previous release was build against Skybrud.Social 0.9.1.1. But as far as I remember, there shouldn't be any breaking changes for the
TwitterHashTagEntity
class, but I'll look into that. For reference, you can see the history of the class/file here:https://github.com/abjerner/Skybrud.Social/commits/master/src/Skybrud.Social/Twitter/Entities/TwitterHashTagEntity.cs
Anyways, if you add
using Skybrud.Social.Twitter.Entities;
to the top of your file, it should work.Just to be sure, if you check the properties of the
Skybrud.Social.dll
, what version does it say? And how did you install/update the package? NuGet or via the Umbraco Package?Hi Anders
Thanks for the swift reply.
I have done a quick check. I noticed I was happily running the version 1.0 with U7.1.8.
The twitter oauth was giving a weird once-in-blue-moon authentication exception, but it normally turned ok after refreshing the page few times - and didnt happen again. So I accepted this is a twitter related delay of some sort and lived with it.
When I see the updated package, tried installing 1.02 on to 1.0.
I encountered the error above when I uploaded 1.0.2, after then I uninstall the package. Then installed 1.01 version. The same exception was thrown. After which i uninstalled 1.01 and installed back the archive 1.0 version.
Then it started working again as normal with 1.0, the exception thrown is exactly the same on 1.02 and 1.01. Now its running on 1.0
I have tried it on two system, so I believe the steps can be replicated (users on 1.0 upgrading to 1.02 (or 1.01) ).
Dll properties from uninstalling 1.01 and back to 1.0: (i.e. version that doesnt throw exception)
It seems the DLL was the same for 1.01, as the previous sshot of the same dll properties looks same:
dll properties from 1.01 package install:
I have checked the partial where the twitter content is fetched and it already has the reference Skybrud.Social.Twitter.Entities
cheers
I'm not sure that I understand - did you experience two separate errors, or just the one that you posted in your first post?
Regarding the error you posted earlier, version 1.0.1 had some breaking changes due to a newer version of Skybrud.Social, so the fix should just be to update your own code a bit. If you can post some more of your code here, I'd be happy to help updating the code to use the newer version ;)
Anyways, if you don't need any of the new logic in Skybrud.Social, it should be fine to stick with Skybrud.Social for Umbraco 7 v1.0.0 (although v1.0.2 fixes an issue if you're using compositions).
Hi Anders
The same error on both 1.01 and 1.02, not two separate errors.
This is the partial code, added try-catch when i get on-and-off twitter authentication errors and couldnt figure out why - repetitive refresh of page solved the issue so i'll let it be.
It seem the < pre > is not working with html, which tag i should use to post so all code with html will be visible here? [EDITED: paste code, select and Ctrl+K ]
Okay, I'll look into that ;) Did you install the NuGet package or the Umbraco package?
Code blocks on Our should be indented with four spaces. You can use the Code Sample button over the editor for this, or just insert your code, select it and press CTRL + K.
Thanks for the heads up. Edited so the code shows properly.
Not using NUGET, installed via Developer->package.
cheers
Hi again,
I had another look at your partial. The problem with the entity classes was that I initially had spelled the class names wrong - eg. the class for a hashtag entity was named
TwitterHashTagEntitity
in earlier versions, but was later renamed toTwitterHashTagEntity
.Also in earlier versions, a call to the Twitter API (eg.
GetUser
method) would return a object or array representing the response body, while in newer versions, the same method will return an object representing the entire response. I have updated this in your partial as well.For reference what I've changed in your partial, you can have a look here: https://gist.github.com/abjerner/565e553e774c9159b320/revisions
Many thanks Anders.
Updated the code, and now using the latest version.
cheers!
is working on a reply...