Unable to render OneNote image resource after appending preAuthenticated=true option in OneNote api call - azure-ad-graph-api

https://github.com/microsoftgraph/microsoft-graph-docs/issues/2624
I am experience the issue as the above.
I am trying to save the content of a page with a reference to an image by calling https://graph.microsoft.com/v1.0/users/{userId}/onenote/pages/{pageId}/content?preAuthenticated=true
Per this - Downloading one note page with image content as HTML
By appending "?preAuthenticated=true" when you do the fetch, it will make the image public.
But when I tried to render the html, it's giving me "Failed to load resource: the server responded with a status of 401 (Unauthorized)".

It appears that something is wrong with the official document: Get OneNote content and structure with Microsoft Graph.
We can see that the service root URL is https://graph.microsoft.com/{version}/{location}/onenote/.
But in any of the samples on this page, the URL is still https://www.onenote.com/api/v1.0/me/notes.
Currently, when you add ?preAuthenticated=true you will get such a URL for a image on this page:
https://graph.microsoft.com/v1.0/users('{userID}')/onenote/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
But when you try to access it in a browser, you will get 401 error Access token is empty.
A workaround is to modify the URL to:
https://www.onenote.com/api/v1.0/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
Then you will get the image.

https://github.com/microsoftgraph/microsoft-graph-docs/pull/4339/files
I think they removed the support for it.

Bit of off topic, but I figured out how to get the image to render.
https://learn.microsoft.com/en-us/graph/api/resource-get?view=graph-rest-1.0&tabs=http
When you call /onenote/pages/{id}/content, the image has a reference to a source like this
src="https://graph.microsoft.com/v1.0/users({userId})/onenote/resources/{resourceId}/$value" along with data-src-type="image/jpeg"
do a get request to this endpoint and you'll the image binary, convert the binary to base64, and then just render the html by replacing the src with base64.

Related

AWS S3 storage does not give a valid URL after uploading file

I am new to AWS. I use Amplify to upload a video file to S3 storage using Flutter. I want to get the URL after uploading a video to use it elsewhere. I use Amplify.Storage.getUrl(key)).url to get the URL. But when I want to go to the link via the browser, it shows the following error there:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>No AWSAccessKey was presented.</Message>
<RequestId>AK49EW70AR8N1NVC</RequestId>
<HostId>Z6FBLU/GABRvJKFX827m3HoIKfVIpU0iXmH3gwSpcu04nNiqqEFjHZGGLn3VyyVNMY7ndK541ro=
</HostId>
</Error>
And also this link doesn't work when I want to play a video using VideoPlayerController.network(videoUrl).
So what is the solution to get a general URL for the video file uploaded that can be used elsewhere? Thanks in advance.

File Upload: File Upload URL not provided

I've been trying to get file uploads to work, following the instructions for both Dropbox and S3 but each time I just get this message:
File Upload URL not provided
It doesn't seem to be making any calls to the server. I've found this mention of a bug around file uploads:
https://github.com/formio/ngFormio/issues/322
But I suspect that applies if you're hosting it yourself. I'm using the cloud version.
I've configured it with e.g. the S3 bucket's URL, authentication etc.
What does this error actually mean?
Update: here's the syntax I'm using:
<formio form="https://formview.io/#/xxxxxxxxxxxxxxxxxxx/applicationform" url="'https://formview.io/#/xxxxxxxxxxxxxxxxxxx/applicationform'"></formio>
Thanks
In order to make the uploads work, you need to provide the URL of your form, which is used to generate the upload token to upload the files to the 3rd party providers. This can be done in one of two ways.
<formio src="'https://examples.form.io/example'"></formio>
You would use above if you wish to render the form from the JSON REST API of the form. In many cases, you may wish to provide the actual form object (which I suspect is what you are doing) like so.
<formio form="{...}"></formio>
This works fine for rendering the form, but it does not provide the URL context for file uploads. For this reason, we have the url parameter which you can include along with your form object for file uploads to work.
<formio form="{...}" url="'https://examples.form.io/example'"></formio>
Providing the url this way is passive. The form will not try to submit to that url, but rather just use it as the url configuration for file uploads.

Facebook API Private Message image expired - How to get new image ? URL signature expired

I'm helping maintain an app that integrates with Facebook, and has lots of archived links to old private message images. Sometimes these images expire, and we go to facebook and request a new image. This works 90% of the time.
About 10% of the time we're getting back a response that we can't tell what the new image is.
What's the proper way to request a new url for an expired Facebook Private Message image, preferably using v2.5 or newer of the Graph API?
Currently we're doing a GET request to Facebook's Graph API using the message id of the private message like so:
https://graph.facebook.com/v2.3/m_mid.XXXXXXXXX:YYYYYYYYY
and that gives us a response that has a bunch of attachments in it. For 90% of use cases, there's a new attachment that has an url or name field with a new filename that contains the old filename, e.g. old file name being XXX, we'd see a new filename like ....XXXX.... in the url field.
attachments [url='*%s*']/image_data/url
attachments [name='*%s*']/image_data/url
or sometimes
picture
but that doesnt match what we get now, which is a bunch of attachments with no way to map to the new image.
We haven't been able to find a graph API way of doing this, but have the following solutions we're considering:
When there's only one attachment in the response, we just use that one url. This works some of the time, but fails when there's more than one image of course
Save more metadata about the image, at worst case an MD5 of the file. Then compare that to MD5's of the other files until we get the one we want. Instead of an MD5, we could consider using info about the file from a HEAD request. All of this is untested.
Update our old message metadata with new metadata whenever this happens, thus avoiding the problem entirely as new image requests would come from the new metadata.

How to get big picture from feed (now)? Api has been changed

I just noticed that Facebook has been changed on retrieving the picture url from feed. Usually I replace _s with _n and I get the "normal" image.
Now I get somthings like this:
https://scontent-b.xx.fbcdn.net/hphotos-xfp1/v/t1.0-9/p130x130/10527490_10152146397901714_1807442783989783336_n.jpg?oh=a4035ad97f2fa1f9a5cf1612e2195662&oe=542053AD
which is only "small". How can I get the bigger one?
You should ideally be using graph api to get pictures.
If however, you need to get bigger image from these type of url links.
First retreive their final url after 302 redirect :
h ttps://scontent-b.xx.fbcdn.net/hphotos-xfp1/v/t1.0-9/p130x130/10527490_10152146397901714_1807442783989783336_n.jpg?oh=a4035ad97f2fa1f9a5cf1612e2195662&oe=542053AD
Remove the bold part, and you will get the original image:
https://scontent-b.xx.fbcdn.net/hphotos-xfp1/10527490_10152146397901714_1807442783989783336_n.jpg?oh=a4035ad97f2fa1f9a5cf1612e2195662&oe=542053AD
EDIT : This method does not work anymore,graph api is the best way to go.

How to post a gallery-image on a users wall

Our app uses the PHP- aswell as the JS-SDK of Facebook. We are able to access the users-images and the images of his friends thru both sdks. The upload of photos into user-albums works aswell.
The user currently selects one of his images which gets manipulated on our server and uploaded to Facebook into the album it came from. That part works. We now want to post that uploaded image onto the users wall. Facebook itself generates a post on the users feed about newly uploaded images (can be disabled on the uploading request) but those posts are not customizable. The standard facebook-post request requires an url to the optional photo. The documentaton states that it is not allowed to link to images from the facebook content delivery-network (which has been confirmed by the graph api as it throws an appropriate error).
Is it possible to create a standard wall-post that contains a gallery-image somehow? Ideally it would use the gallery-popup but that is clearly super-nice-to-have.
An externally hosted copy is an (unwanted) workaround that we already know. Reuploading the image is an option as long as it does not show up in the gallery twice.
Simple solution :
Get a tinyurl for you fbcdn'ed picture through tinyurl api:
Example with url from above :
http://tinyurl.com/api-create.php?url=http://a4.sphotos.ak.fbcdn.net/hphotos-ak-snc3/13943_196960329960_683709960_2997879_7206516_n.jpg
Returns :
http://tinyurl.com/3ta96kh
Then use this url as the "picture", I tried it here and it works ! : http://jsfiddle.net/dwarfy/VYAeD/27/
There was another solution here but It seems facebook corrected it and it still says the error with facebook CDN when I post using https://graph.facebook.com/PICTURE_ID as picture instead of the FBCDN image url.
I think it's the best solution ...
My example doesn't use the link parameter but you could set it to the gallery image ...
Indeed you can't post to users' walls image saved on fb BUT also you don't have to save it physically on you server. if you want to post an image, for example:
http://a4.sphotos.ak.fbcdn.net/hphotos-ak-snc3/13943_196960329960_683709960_2997879_7206516_n.jpg
facebook as you know will not accept this. but ther is no problem to post something like this: http://yourserver.com/script.php?image=a4.sphotos.ak.fbcdn.net/hphotos-ak-snc3/13943_196960329960_683709960_2997879_7206516_n.jpg (without http:// -- its important, if you include http:// facebook will find out what's going - and we don't want it:)
script.php is a php file on your server that do this:
<?
$url = "http://".$_GET['image'];
header('Content-type: image/jpeg');
echo file_get_contents($url);
?>
or something like this:
<?
$url = "http://".$_GET['image'];
$image = imagecreatefromjpeg($url);
//some image modifications here//
header('Content-type: image/jpeg');
echo imagejpeg($image, null, 100);
?>
you can also add an database with urls and post something like this: http://yourserver.com/script.php?imageid=ID hiding all images' real paths.
If you want to save on traffic after publishing images on walls just redirect:
<?
//if published then just redirect
$url = "http://".$_GET['image'];
header('Location: '.$url); die();
?>
You have to make the copy of that image otherwise there is no way you can use this image in standard post dialog.
Use PHP function
copy()
I know you are looking for any other alternative but to create a spare image on your server or any other server is the only solution.