My Links (Quick Links of an user) is available in My Site of the user from SharePoint Server 2007 and I believe “My Links” link was part of user profile menu at the top of the page in SP2007.
In SharePoint Online, I did not see an easy way to get to users' “My Links”. The easiest way to get to “My Links” of a user is through this URL,
https://tenantname-my.sharepoint.com/_layouts/15/MyQuickLinks.aspx
We had a requirement for users to save their favorite links on our intranet home page. So we decided to use “My Links” to allow users to save their links. So, now how do we show these links on the intranet home page as the intranet site collection is different from “My Site” site collection.
One way was to use the “QuickLinks” web part which is available out-of-the-box in SharePoint, but it is available out-of-the-box only in the “My Site” site collection.
We found out that the web parts available in “My Site” can be downloaded and uploaded into other site collections and it will be available for us to use in that site collection.
To do this, we had to go to web part gallery of “My Site” site collection. The URL for that is – https://{tenantname}-my.sharepoint.com/_catalogs/wp/Forms/AllItems.aspx
In My site web parts gallery, you can see many web parts available, but not all of them will work in other site collections. We are interested in quicklinks.dwp and it definitely works in site collections other than “My Site” site collection.
So, we downloaded this from web part gallery of my site and uploaded it into the web part gallery of the intranet site collection.
Once this is done, if you edit any page and add web part, you will see these web parts under “Default Web Parts” and as you can see we now have the “QuickLinks” web part available to add to the page. Once added, it will show the favourite links of the logged in user as shown below –
This was good, but did not give the exact look and feel we wanted for our intranet. Also, we wanted to add a link for user to get to https://{tenantname}-my.sharepoint.com/_layouts/15/MyQuickLinks.aspx, so they can manage their favourite links by adding, deleting, editing etc.
So, we developed a custom component to get “My Links” of the user. Below is the code –
- function quickLinksViewModel() {
- var self = this;
- self.myQuickLinks = ko.observableArray();
- self.getMyQuickLinks = function(loginName) {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_vti_bin/UserProfileService.asmx/GetUserLinks",
- method: "POST",
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- data: "{accountName:'" + loginName + "'}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function(data) {
- self.myQuickLinks(data.d);
- },
- error: function(jqxr, errorCode, errorThrown) {
- console.log(jqxr.responseText);
- }
- });
- };
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentUser",
- method: "GET",
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data) {
- self.getMyQuickLinks(data.d.LoginName);
- },
- error: function(data) {
- alert(data.error);
- }
- });
- }
- $(document).ready(function() {
- ko.applyBindings(new quickLinksViewModel(), document.getElementById("divMyLinks"));
- });
- <div id="divMyLinks" class="panel panel-default">
- <!-- Todo: Generate table body -->
- <div class="panel-heading" style="color: #ac1a2f;"><span class="ms-Icon ms-Icon--link"></span> My Links</div>
- <div class="panel-body">
- <div data-bind="foreach: myQuickLinks"> <span class="ms-Icon ms-Icon--link" style="color: #ac1a2f;"></span> <a data-bind="attr:{href: Url}" target="_blank"><span data-bind="text: Name"></span></a></div> <span>This space shows your personal quick links. Use "Manage Links" to create your quick links. </span> <a target="_blank" class="btn btn-default" style="border-color:#ac1a2f;color:#ac1a2f" href="https://{tenantname}-my.sharepoint.com/_layouts/15/MyQuickLinks.aspx">Manage Links</a></div>
- </div>
If you see the code, we get the current user by using the REST API {sitecollectionurl]/_api/web/currentUser.
There are multiple ways to get user information in SharePoint Online, but not all of them give the user quick links (my links). We tried using REST API for User Information List which does not have quick links information. Then we tried using SP.UserProfiles.js to get all user properties from User Profile service and this gives the property “QuickLinks” and it is always empty.
So, the only working option was to use the old web service UserProfileService.asmx. If you check the URL {sitecollectionurl}/_vti_bin/UserProfileService.asmx in Chrome, this will show you all the available methods under this web service and what we need is “GetUserLinks”
As you can see in the JavaScript code, the only parameter it needs is User Account name as input and the output is all links (Name, URL, Group) that user has saved as their favourites. The UI would look like –
Now, users can save their favorite links in SharePoint My Site and see them and manage them from the Intranet home page. Hope this is useful for someone.