Sorry for the Razor examples being a bit out of date. I thought for sure I had updated them with the latest release.
Here is an updated example:
@using Skybrud.Social.Instagram
@using Skybrud.Social.Instagram.Objects
@using Skybrud.Social.Instagram.Responses
@using Skybrud.Social.Umbraco.Instagram.PropertyEditors.OAuth
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
// Get the OAuth information stored in the property
InstagramOAuthData instagram = Model.GetPropertyValue("instagram") as InstagramOAuthData;
// Check whether the OAuth data is valid
if (instagram != null && instagram.IsValid) {
// Gets an instance of InstagramService based on the OAuth data
InstagramService service = instagram.GetService();
// Gets information about the authenticated user
InstagramUserResponse self = service.Users.GetSelf();
// Get recent media from the authenticated user
InstagramRecentMediaResponse recent = service.Users.GetRecentMedia(self.Body.Data.Id);
<fieldset>
<legend>Instagram</legend>
<p>@(self.Body.Data.FullName ?? self.Body.Data.Username) (ID: @self.Body.Data.Id)</p>
<hr />
@foreach (InstagramMedia media in recent.Body.Data) {
<img src="@media.Thumbnail" alt="@media.CaptionText" />
}
</fieldset>
}
}
That seems right. Actually when writing @Html.Partial("instagram"), ASP.NET will look for an instagram.cshtml in a number of folders, where ~/Views/Partials/ is one of them. So that part should be okay.
Just to rule things out, I have a few questions to your solution/site:
What is the alias of your property? If you call Model.GetPropertyValue("instagram"), the alias of your property should be instagram.
Is the page you're viewing the same as the page the property has been added on? Depending on your use case, you may have added the property to the root page, but trying to use it on a sub page. My example just assumes the property has been added to the page being viewed, so if that this isn't the case, you should adjust the example a bit.
I have a master.cshtml, a homepage.cshtml and the instagram.cshtml
Views
Homepage.cshtml
master.cshtml
Partials
instagram.cshtml
In my master, I call
@Html.Partial("instagram")
and this successfully finds my instagram.cshtml file within the partials folder. I know this because I put a breakpoint in and stepped through the process.
I think I must be missing a fundamental thing here. I am trying to run it on localhost, would that be a problem?
I've called the datatype instagram.
In the admin area, go to developer tab and create a new data type. I called mine instagram and then entered in my instagram developer credentials which you find at https://instagram.com/developer/clients/manage/
In the admin area, go to settings tab and create a new partial view, I called mine instagram and paste the following code in.
// Get the OAuth information stored in the property
InstagramOAuthData instagram = Model.GetPropertyValue("instagram") as InstagramOAuthData;
// Check whether the OAuth data is valid
if (instagram != null && instagram.IsValid) {
// Gets an instance of InstagramService based on the OAuth data
InstagramService service = instagram.GetService();
// Gets information about the authenticated user
InstagramUserResponse self = service.Users.GetSelf();
// Get recent media from the authenticated user
InstagramRecentMediaResponse recent = service.Users.GetRecentMedia(self.Body.Data.Id);
<fieldset>
<legend>Instagram</legend>
<p>@(self.Body.Data.FullName ?? self.Body.Data.Username) (ID: @self.Body.Data.Id)</p>
<hr />
@foreach (InstagramMedia media in recent.Body.Data) {
<img src="@media.Thumbnail" alt="@media.CaptionText" />
}
</fieldset>}}
Go to settings tab, expand Document type and find the document type you would like to add the instagram feed to. I put mine on the homepage. Click on the document type, then click on the Generic Properties tab. Click 'Add new property', give it a name but make sure the alias is instagram. In the Type dropdown menu, select instagram. I put this in the Generic Properties tab. Save.
Go to the Content tab, click on the page you have placed the type on, in my example, Homepage. Click the properties tab, scroll down until you see your property, there should be an authorize button showing. Click it. This will authroize your site to communicate with instagram. If successful, you should see your instagram avatar and username.
Go to the page template that you want your feed to display on and enter
I followed the steps but when i create a partial view "instagram.cshtml" in umbraco backoffice, automatically "_InstagramPartialView.cshtml" gets created in Views/PartialView and when i click on the page i get an error message " The Item doesnt exist in the project Directory. It may be moved, renamed or deleted ." Please let me the issue.
the error is Could not load type 'Skybrud.Social.Umbraco.App_Plugins.Skybrud.Social.Dialogs.InstagramOAuth'. when i click the authorize button
My bad I didnt install the package in umbraco Backoffice. But now when i have installed and click Authorize button as mentioned in the above process i get a message "Hold on now! The options of the underlying prevalue editor isn't valid." in a new pop up window.
I have a different version now as well which runs fine on my live site:
@using Skybrud.Social.Instagram
@using Skybrud.Social.Instagram.Objects
@using Skybrud.Social.Instagram.Responses
@using Skybrud.Social.Umbraco.Instagram.PropertyEditors.OAuth
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
// Get the OAuth information stored in the property
var currentContent = Umbraco.TypedContent(UmbracoContext.PageId.Value);
var rootNode = currentContent.AncestorOrSelf(1);
var instagram = rootNode.GetPropertyValue<InstagramOAuthData>("instagram");
// Check whether the OAuth data is valid
if (instagram != null && instagram.IsValid) {
// Gets an instance of InstagramService based on the OAuth data
InstagramService service = instagram.GetService();
// Gets information about the authenticated user
InstagramUserResponse self = service.Users.GetSelf();
// Get recent media from the authenticated user
InstagramRecentMediaResponse recent = service.Users.GetRecentMedia(self.Body.Data.Id, 4);
<fieldset>
@foreach (InstagramMedia media in recent.Body.Data) {
<a href="@Umbraco.Field("instagramSocial")"><img src="@media.Thumbnail" alt="@media.CaptionText" height="110px" width="110px" /></a>
}
</fieldset>
}
}
This instagram is always null.
I tried including "\App_Plugins\Skybrud.Social" into the project and i am getting compile time errors . Should it be included in the project ??
As this appears to be another issue that the one Owain originally described in this thread, could you create a new thread with your issue? Then I'd be happy to have another look at it ;)
Instagram help.
Hi, I'm new to umbraco and also to SkyBrud.Social.
I'm currently trying to work my way through the online examples to pull in 9 of my latest photos from Instagram.
I have created a partial view in Umbraco, using the cshtml provided on the wiki. That is through up errors on the line:
I'm getting an error at the end, under Data. (...does not contain a definition for Data and no extension method....)
What am I missing?
I've installed SkyBurd.Social package in to Umbraco and I have entered in my client ID etc in to the newly created datatype.
Would someone be kind enough to share their partial class and front-end solution?
Thanks,
Hi Owain,
Sorry for the Razor examples being a bit out of date. I thought for sure I had updated them with the latest release.
Here is an updated example:
Thanks Anders,
I've placed the partial view within the Views\Partials folder is that correct?
Then on my homepage masterpage I have put @Html.Partial("instagram") but nothing is showing on my site - obviously I've made a mistake somwhere!
I've also installed the Skybrud package and created the new document type and entered all my instagram developer details.
Is returning null, so this is obviously where it's failing, what could cause this?
Hi again,
That seems right. Actually when writing
@Html.Partial("instagram")
, ASP.NET will look for aninstagram.cshtml
in a number of folders, where~/Views/Partials/
is one of them. So that part should be okay.Just to rule things out, I have a few questions to your solution/site:
What is the alias of your property? If you call
Model.GetPropertyValue("instagram")
, the alias of your property should beinstagram
.Is the page you're viewing the same as the page the property has been added on? Depending on your use case, you may have added the property to the root page, but trying to use it on a sub page. My example just assumes the property has been added to the page being viewed, so if that this isn't the case, you should adjust the example a bit.
Thanks for your continued help with this!
I'll try and explain my setup.
I have a master.cshtml, a homepage.cshtml and the instagram.cshtml
Views
Partials
In my master, I call
and this successfully finds my instagram.cshtml file within the partials folder. I know this because I put a breakpoint in and stepped through the process.
I think I must be missing a fundamental thing here. I am trying to run it on localhost, would that be a problem? I've called the datatype instagram.
Sorry about this!
Think I have found the issue. I hadn't added the instagram property to my homepage!
If I get a chance, I'll put some instructions together to help others in the future. :)
Here are the steps I took to get an instagram feed working on my site.
Download the instagram package from https://our.umbraco.org/projects/website-utilities/skybrudsocial-for-umbraco-7 and installed it on my site.
In the admin area, go to developer tab and create a new data type. I called mine instagram and then entered in my instagram developer credentials which you find at https://instagram.com/developer/clients/manage/
In the admin area, go to settings tab and create a new partial view, I called mine instagram and paste the following code in.
Go to settings tab, expand Document type and find the document type you would like to add the instagram feed to. I put mine on the homepage. Click on the document type, then click on the Generic Properties tab. Click 'Add new property', give it a name but make sure the alias is instagram. In the Type dropdown menu, select instagram. I put this in the Generic Properties tab. Save.
Go to the Content tab, click on the page you have placed the type on, in my example, Homepage. Click the properties tab, scroll down until you see your property, there should be an authorize button showing. Click it. This will authroize your site to communicate with instagram. If successful, you should see your instagram avatar and username.
Go to the page template that you want your feed to display on and enter
Where you want the feed to display.
Hope this helps others to get this working.
Hi Williams,
I followed the steps but when i create a partial view "instagram.cshtml" in umbraco backoffice, automatically "_InstagramPartialView.cshtml" gets created in Views/PartialView and when i click on the page i get an error message " The Item doesnt exist in the project Directory. It may be moved, renamed or deleted ." Please let me the issue.
the error is Could not load type 'Skybrud.Social.Umbraco.App_Plugins.Skybrud.Social.Dialogs.InstagramOAuth'. when i click the authorize button
Hi, Do you have the Skybrud.Social package installed in Umbraco?
You can find it here: https://our.umbraco.com/packages/website-utilities/skybrudsocial-for-umbraco-7/
Owain.
Hi Williams,
i already have installed Skybrud.Social for Umbraco 7 in my visual studio. Still i am facing the error.
Hi, Could you share your code so that I can see what might be causing the error?
Thanks, Owain.
Hi Williams,
My bad I didnt install the package in umbraco Backoffice. But now when i have installed and click Authorize button as mentioned in the above process i get a message "Hold on now! The options of the underlying prevalue editor isn't valid." in a new pop up window.
When you have come to the point where you're able to click the Authorize button, you should already have an Instagram data type in Umbraco.
The error message you're seeing is probably because you haven't yet entered the necessary about your Instagram app. Could that be the issue?
Hi,
Thanks i could authenticate the instagram, but after authenticating i added the partial view. and still i am not able to fetch any value in instagram.
I made the same steps, but I've always a null value from this:
I'm sure 100% that field and alias are correct and in the page. The code is into a partial view.
Hi, Did you use the code exactly as it is above?
I have a different version now as well which runs fine on my live site:
Hi,
var instagram = rootNode.GetPropertyValue
This instagram is always null. I tried including "\App_Plugins\Skybrud.Social" into the project and i am getting compile time errors . Should it be included in the project ??
So can you help me with this ??
Hi again,
As this appears to be another issue that the one Owain originally described in this thread, could you create a new thread with your issue? Then I'd be happy to have another look at it ;)
Thanks for the reply.
I have created a new thread of my issue . Please find the link below:
https://our.umbraco.com/forum/templates-partial-views-and-macros//95370-skybrudsocialinstagram-help
is working on a reply...