I have sent a request to Microsoft Graph, to get the photo from the user.
It looks like this --GET https://graph.microsoft.com/v1.0/users/USER_ID/photo/$value
I get, as a response, binary format of an image, and as doc suggests I made blob object,
like this.
Type od data(from image) that I recieve, I set to be ng.HttpPromise.
I get url, that I set for image src (in html), but photo isn't showing, and I don't have any Error popped up.
To get a user's photo using Graph, use: https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/photo/$value.
From the sample shared(see below) I can see a minor mistake:
Once the response completes, you need to call data.blob() which returns a promise containing the blob, which you can then pass to createObjectUrl after resolution.
this.videoEventServie.getPersonPhoto(contact).then(data => {
return data.blob();
}).then(function(currentBlob){
var src= URL.createObjectURL(currentBlob);
myImage.photoUrl = src;
});
Please see this answer: Using JavaScript to display a Blob for additional context.
Related
I'm trying to implement Story Mention rendering according to IG messenger graph API.
IG webhooks sends the payload URL of the media as CDN URLs that are extensionless,
which means I can't detect the file type(could be any kind of image or a video file).
The purpose is to render the URL to an HTML element and to prevent saving some file extensions.
Did anybody find out how to get this information?
An example for IG CDN URL
https://lookaside.fbsbx.com/ig_messaging_cdn/?asset_id=17952754300482708&signature=AbxVoHUcW3qKGZvE0FwrbpSEKBqkYGH9wFDUY9xnywlxxek8lWtrTwE173Sxhta9jbp0bgDiL17IpyiI82vqHGNPUD1wdMUZphwQOggW-_877cCI1BxaY_aDUZ8hj5OwmHK9E8OnSybqtMVmGXCX_hBF399t1Hb44zspeL3d9NWb9rib
Python:
import requests
res = requests.head(url)
print res.headers
I was able to retrieve the content type by making a request with node-fetch.
const fetch = require('node-fetch');
const response = await fetch(mediaUrl, { method: 'HEAD' });
const contentType = response.headers.get('Content-Type');
I am using the Facebook Graph API to get the news feed of a user.
My request URL is:
xxxxxxxxxxxxxx/feed?fields=from,id,created_time,picture,link,object_id,message, likes.fields(id)
With the object_id, I want to get the big picture of the post, using the following url:
http://graph.facebook.com/OBJECT_ID/picture?type=normal
The picture return field is always filled, but the object_id is not being returned at some posts. Why is this? I really need the high res picture, and didn't find another way to acquire this..
The object_id is only returned if the attachment is a facebook object (e.g. an image uploaded by the user). Some stories in feed don't have a picture at all, and some pictures are not facebook objects (e.g. thumbnails for shared links).
Sometimes Facebook keeps a thumbnail of an image and stores an external link to the larger version of the image in the URL returned by the graph request. In order to access the images in either case, I used the code below, where smallURL is the URL returned by the graph request:
private String getRealURL(String smallURL){
if (smallURL.contains("url=http")){
String[] pieces = smallURL.split("url=");
pieces[1].replace("%2F", "//");
pieces[1].replace("%3A", ":");
return pieces[1];
}
else{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.setLength(0);
stringBuilder.append("http://graph.facebook.com/");
stringBuilder.append(item.getObjectID());
stringBuilder.append("/picture?type=large");
return stringBuilder.toString();
}
}
I also noticed that some FB posts didn't have {object_id} for large photos, but realized that the {picture} thumbnail URL contains the encoded URL of the original larger image:
https://external.xx.fbcdn.net/safe_image.php?d=AQBe9UvGd0vPbAHP&w=130&h=130&url=http%3A%2F%2Fskift.com%2Fwp-content%2Fuploads%2F2015%2F12%2Fpollution.jpg&cfs=1
--> contains -->
http://skift.com/wp-content/uploads/2015/12/pollution.jpg
So I check for {object_id}, and if not then try to extract the original URL from {picture}:
if(isset($post['object_id'])) {
echo "http://graph.facebook.com/".$post['object_id']."/picture";
}
elseif(isset($post['picture'])) {
echo urldecode(preg_replace('/&cfs.*/', '', preg_replace('/.*url=/', '', $post['picture'])));
}
else {
echo "no_large_image";
}
I want the user to be able to upload a file via my application. I don't have DB access, all my data calls get completed via a web-service that another person is writing. I needed to secure the web service, so I've consumed it & exposed it via WebAPI, & added OAuth security.
Now to my problem.
I've written the following.
public Task<FileResult> Post()
{
if (Request.Content.IsMimeMultipartContent())
{
var task = Request.Content.ReadAsByteArrayAsync().ContinueWith(
o =>
{
var result = this.Client.UploadPicture(this.UserId, o.Result);
if (result.ResultCode == 0)
{
return new FileResult()
{
Message = "Success",
FileId = result.ServerId
};
}
throw new HttpResponseException(...);
});
return task;
}
...
}
I'm pretty much a noob when it comes to WebAPI & multithreading (I'm not sure why this needs to be handled async? I'm sure there is a reason, but for now I'd just like a working example and get to the why later..).
My code is loosely based on some R&D & samples I've found on the net, but i haven't come across a scenario like I'm needing to complete... Yet it doesn't seem like I'm doing something out of the ordinary...
Upload a file to the server, and pass the image byte[] object to either sql or another service?
In this line
var result = this.Client.UploadPicture(this.UserId, o.Result);
I'm uploading a byte[] array of something....
Then later (the retrieval method works, I've managed to retrieve & view a test image)
When retrieving the byte array of the "image" i uploaded i get an array of idk what.. EG, i get a valid result of something, but it ain't no picture. Which leads me to believe that the uploaded data is bogus :|
O_o
How to get the image byte[]?
Mime Multipart is more than just your array of bytes. It also has metadata and boundary stuff. You need to treat it as MultiPartContent and then extract the image byte array out of that.
Filip has a blog post on the subject here.
Using the using the Facebook Graph API/SDK for iOS I'm getting the users News Feed with https://graph.facebook.com/me/home. Some of the news feed items return a "story":"xxx" in the JSON response, if the stories contain an image it will be accompanied by a "picture" element. The picture element always returns the small image size.
Here is an example:
"id":"100000238965505_364153823602580",
"from":{
"name":"Cristine Candelaria",
"id":"100000238965505"
},
"story":"Cristine Candelaria was tagged in Arielen Magno Bismar's photo.",
"picture":"http:\/\/photos-g.ak.fbcdn.net\/hphotos-ak-snc7\/431768_2610303545476_1491618385_31927362_2089838362_s.jpg",
"link":"http:\/\/www.facebook.com\/photo.php?fbid=2610303545476&set=at.2610291065164.2111576.1491618385.100000238965505&type=1",
"icon":"http:\/\/static.ak.fbcdn.net\/rsrc.php\/v1\/yz\/r\/StEh3RhPvjk.gif",
"type":"photo",
"object_id":"2610303545476",
"application":{
"name":"Photos",
"id":"2305272732"
}
I've tried using what Facebook recommends in the API https://graph.facebook.com/2610303545476/picture, however this always returns a false in the JSON response and I've also tried just getting the feed details via [Graph API URL]/100000238965505_364153823602580 (sorry I can only post 2 hyperlinks). This does not yield any extra usefully information.
I've discovered that if you manipulated the end of the "photo" element URL and simply switch the _s to _n you will get the normal image size.
My question is what's the proper way to get the image and the text associated with that image (ex: first time at the super bowl...) for a News Feed using the Graph API?
I am trying to develop an IMAP email client using the javax.mail API. I have been able to contact the servers, fetch emails, attachments and other operations without any problem.
However, we would not want to fetch the attachment until the user wants to view it explit in order to improve the performance. This would mean that we would need information which would indicate if the email has an attachment, if yes, then the filename(s) and the size(s)but would not send me the actual content of the email. However, I was not able to find a method in the API description which would return just the multi-part content.
Is there a way I could fetch just the body and the details of the attachment but not the actual attachment?
Thanks,
Aravind
The method getContent() of javax.Part returns
the content as a Java object. The type
of the returned object is of course
dependent on the content itself. For
example, the object returned for
"text/plain" content is usually a
String object. The object returned for
a "multipart" content is always a
Multipart subclass.
See http://download.oracle.com/javaee/6/api/javax/mail/Part.html#getContent%28%29
If a Message (which is a Part) contains attachments, the getContent method will return a Multipart object. In addition you can know the MIME type of the part with getContentType.
The information that is missing from the documentation is that this MultiPart object returned by getContent is just an empty representation of the Message's structure. The content of each Part of the Multipart will only be fetched from the server when you specifically ask for it. For example, to parse a multipart Message you would do:
if( p.isMimeType("multipart/*") ) {
Multipart mp = (Multipart)p.getContent();
// the content was not fetched from the server
// parse each Part
for (int i = 0; i < mp.getCount(); i++) {
Part inner_part = mp.getBodyPart(i)
if( inner_part.isMimeType("text/plain") ) {
String text = inner_part.getText();
// the content of this Part was fetched from the server
}
}
}
Something else to consider is that for optimal performance you should get the body structure information from the server in batch for the collection of messages you want to parse (see http://download.oracle.com/javaee/6/api/javax/mail/FetchProfile.Item.html#CONTENT_INFO). If not, each
Multipart mp = (Multipart)p.getContent();
will result in a request to the server to fetch the body structure. If the FetchProfile approach is used, the body structure for the collection of messages will be fetched with only one request. You can see the requests to the server in the log if you activate debug mode on the session:
session.setDebug(true);
This said, to get size and filenames of attachments just use Part.getSize() and Part.getFileName(), respectively.