I'm sorry if I haven't made it clear, but v1.0.1 uses a newer version of Skybrud.Social (that has some breaking changes).
For your example, the change is however rather small - so rather than:
TwitterUser user = service.Users.GetUser(twitter.Id);
You should write:
TwitterUser user = service.Users.GetUser(twitter.Id).Body;
The reason for this change is so that the call to the API will return information about the entire response (eg. Twitter send rate limiting information in the HTTP headers).
How would your original example look in relation to the new version?
@using Skybrud.Social.Twitter
@using Skybrud.Social.Twitter.Objects
@using Skybrud.Social.Umbraco.Twitter.PropertyEditors.OAuth
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
// Get the OAuth information stored in the property
TwitterOAuthData twitter = Model.GetPropertyValue("twitter") 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);
<fieldset>
<legend>Twitter</legend>
<p>@user.Name (ID: @user.Id)</p>
<hr />
@foreach (TwitterStatusMessage status in recent.StatusMessages) {
<p>@status.Text</p>
}
</fieldset>
}
}
When adding .Body to the TwitterService, I just get a new error on the TwitterTimeline.
@using Skybrud.Social.Twitter
@using Skybrud.Social.Twitter.Objects
@using Skybrud.Social.Umbraco.Twitter.PropertyEditors.OAuth
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
// Get the OAuth information stored in the property
TwitterOAuthData twitter = Model.GetPropertyValue("twitter") 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).Body;
// Get recent status messages (tweets) from the authenticated user
TwitterStatusMessage[] recent = service.Statuses.GetUserTimeline(user.Id).Body;
<fieldset>
<legend>Twitter</legend>
<p>@user.Name (ID: @user.Id)</p>
<hr />
@foreach (TwitterStatusMessage status in recent) {
<p>@status.Text</p>
}
</fieldset>
}
}
// Get the response for the status (tweet)
TwitterStatusMessageResponse response = service.Statuses.GetStatusMessage(statusId);
// Get the tweet from the response
TwitterStatusMessage tweet = response.Body;
// Write the text on the page
@Html.Raw(TwitterUtils.FormatEntities(tweet.Text, tweet.Entities))
This will format hashtags, URLs and mentions. The Twitter API doesn't specify any information about emojis in a tweet, so you will have to find a way to deal with this manually.
Since images are not actually a part of the text, you can grab the first image via:
if (tweet.Entities.Media.Any()) {
TwitterMediaEntity media = tweet.Entities.Media[0];
<a href="@media.DisplayUrl" target="_blank"><img src="@media.MediaUrl" alt="@media.MediaUrl" /></a>
}
The array will ways be either empty or contain a single image - even if the tweet contains contains multiple images. This is due to the structure of the JSON received from the Twitter API.
The API has another property containing information about all media/images, but this is currently not supported in Skybrud.Social.
Cannot implicitly convert type
I am getting:
From this:
I am using the exact same code with Skybrud.Social for Umbraco 7 v1.0.0 package on another site.
What has changed from v1.0.0 to v1.0.1 and how do I fix the problem?
Hi,
I'm sorry if I haven't made it clear, but v1.0.1 uses a newer version of Skybrud.Social (that has some breaking changes).
For your example, the change is however rather small - so rather than:
You should write:
The reason for this change is so that the call to the API will return information about the entire response (eg. Twitter send rate limiting information in the HTTP headers).
How would your original example look in relation to the new version?
When adding .Body to the TwitterService, I just get a new error on the TwitterTimeline.
Hi Søren,
An updated example would look something along:
Thanks! That did the trick! :)
How do I format urls and hashtags in a status message?
On the GitHub repository there is a folder called Formatting, so I assume it is possible?
You can use the
TwitterUtils
class for that:This will format hashtags, URLs and mentions. The Twitter API doesn't specify any information about emojis in a tweet, so you will have to find a way to deal with this manually.
Since images are not actually a part of the text, you can grab the first image via:
The array will ways be either empty or contain a single image - even if the tweet contains contains multiple images. This is due to the structure of the JSON received from the Twitter API.
The API has another property containing information about all media/images, but this is currently not supported in Skybrud.Social.
That did the trick! Thanks! :)
Thanks Anders! :)
is working on a reply...