Can I do this with SPServices

Dec 17, 2011 at 12:21 AM

I have piece of work to do for a client which involves exposes a list of calendar events in another website.  I've seen the potential of SPServices but what I need to know his.  Can I use this in a different domain to where the sharepoint application lives?  I have been given access to the webservices but thats all.  All I want to do is be able to consume the calendar of events and display in another website.  The reason I post this is that I cannot find any example or documentation where I pass into the SPService script the url of where to get the data from, which lead me to think it was only possible if you were on the same domain.  Someone please advise as this looks a great fit to my problem but not sure if it can be used in my situation for reasons stated above.  Someone please advise.  Also I've never used SharePoint and I have 4 days to come up with the finished goods.



Dec 17, 2011 at 12:50 AM

g_r_a_robinson,

If your question is really on a "different domain" (ex. http://my.site1.com and http://your.site2.com, then no... This is not a limitation of this library, but a browser security feature; you can not x-domains.  The only real way to "x-domains" is to use jsonp "trick", but to my knowledge, SP does not support that approach.

However,

If what you mean is that you have two sharepoint sites within the same domain (ex. http://my.site1.com/webs/subsite1 and http://my.site1.com/webs/subsite2), then yes, you can pulll in data from the "other" site.  Just about all methods of this library accept an input parameter named 'webURL', which you can define to point to a different Site (within the same domain)...

Paul.

Dec 17, 2011 at 12:57 AM

Really quick response and thanks.  Yes, my second non sharepoint site is on a different domain/server and the client has only opened up the webservices to me and provided the necessary authentication credentials.  Is there no way I can let visual studio create the usual wsdl proxies (web service references) and then have the client side spservices call this as an alternative to calling sharepoint directly.  I really don't want to have to write a whole calendar control when someone has already done it and the only problem i have is the browser security getting in the way.  Please advise.

Dec 17, 2011 at 1:06 AM

Not through SPService that I know of... I had to implement something similar in an app I developed on SharePoint that pulled data from a unix server (running apache)... The only way I did it was to write a perl cgi program to return the data in jsonp format.

You should write your proxy to return json notation instead wrapped in a javascript function... one of the properties in the jsonp object could be xml: '<your xml response here'....

Not sure if SPServices can be used in that case, being that its calls to the server are not designed to trigger jsonp (I think jquery requires you to set a parameter in the url called 'callback'

Good Luck.

Paul.

Dec 17, 2011 at 1:11 AM

Also if none of the above is possible.  Would it work if I could get the client to provide anonymous access just to the calendar events?  Would I be able to make the web service call this way.  Although I still see no option to pass in the URL of a different domain based sharepoint via the spservice library???

Dec 17, 2011 at 2:03 AM

No it can't be done

You need to read this: http://en.wikipedia.org/wiki/Same_origin_policy

Has nothing to do with the other site giving anonymous access...

Dec 17, 2011 at 12:43 PM

Before I can give my complete thought on this I need to understand exactly what is happening. If I understand what you are saying, you have a SharePoint site and you want to have a page on that site that shows calendar events from a non SharePoint site. Is this correct? Do users have access to the page that has the events on it or do they just have the web services exposed?

Dan

Dec 17, 2011 at 1:13 PM

No, the other way around.  I have been given access to a sharepoint site and my client wants the calendar events from this instance of sharepoint to be made available in another website (on a different server/domain).  They have given me the webservice access (credentials) to access it.

The instance of sharepoint is on an intranet, so only internal users access it but they want the calendar to be exposed via this second non sharepoint website.

Hope it helps.

Dec 17, 2011 at 1:43 PM

Okay, ptavares is correct and I just wanted to be sure. SPServices can not do it, but you can access the web services maybe through a proxy but it will require a lot more work on your part to set that up. The JSONP format is a good choice and I think there is another one as well that involves yahoo pipes ore something.

Coordinator
Dec 17, 2011 at 2:31 PM
What about AJAXing the SharePoint page that has the calendar on it, stripping out the calendar part of it, and displaying that in an iframe on the other site?

If you want to show the calendar looking like the SharePoint calendar, that's the only way I can think of doing it.

M.
Dec 17, 2011 at 2:55 PM
I thought about that but wasn't sure if the security model would allow that across domains. If it works though...

Sent from my iPhone

On Dec 17, 2011, at 9:32 AM, "sympmarc"<notifications@codeplex.com> wrote:

From: sympmarc

What about AJAXing the SharePoint page that has the calendar on it, stripping out the calendar part of it, and displaying that in an iframe on the other site?

If you want to show the calendar looking like the SharePoint calendar, that's the only way I can think of doing it.

M.
Dec 17, 2011 at 3:28 PM

Marc, spevilgenius,

Yes, that does sound like an approach... the manipulation of the presentation of the calendar is done on SP (ex.: perhaps hide everything (like navigation bars, headers, etc), so that when displayed on the "external" site in an iFrame, it shows only the calendar...  It does not sound, however, like he may have control over the SP page that displays the calendar.

I use a similar method (although, all within SP)... Page 1 shows a piece of Page 2 in an iFrame.... On page 1, I define the iframe to call page2 with a url parameter of "?mode=embedded". On page2, I have javascript code that check the URL for the document and it it contain a parameter named 'mode' and that parameter value is 'embedded', then it hides entire page ($('form:first').children().css("display", "none").addClass("pt-visible-on-load"))... then I show only the piece I want to make visible (in my case, I "grab" it and move it to be displayed inside of the <form>).

Paul.