Generating Anonymous links to O365 documents

There was this great question in the MSDN forums:

http://social.msdn.microsoft.com/Forums/en-US/461c8c04-35f6-455f-bb24-e3fb9ac08dfc/rest-api-function-for-generating-guest-link?forum=sharepointdevelopment

Which I prompted replied with the endpoint you make a POST to:

https://tenanturl.sharepoint.com/_layouts/15/aclinv.aspx?obj={1bb8fb61-41d7-4c12-9c7e-e33961476439},1,DOCUMENT&List=1bb8fb61%2D41d7%2D4c12%2D9c7e%2De33961476439&command=createlink&readwrite=false

Where the object id is the list id followed by a comma, then the
list item id.  The list query string is the list id (with dashes).  That
will simply return a link with an access token that anyone can use.

You can then take that link and send it out to people in your app (NOTE:  A SharePoint "App" cannot make a call to this SharePoint Online end point, you must execute the Http request as a user with FedAuth or SPO identity cookie).