Dropbox - IOS- Swift 3 : Cannot get the thumbnail image - ios

I am trying to populate my collection view with images from the dropbox.
I want to have the thumbnail image for my grid view (collection view) with the following code.
DropboxClientsManager.authorizedClient?.files.getThumbnail(path: filename).response(completionHandler: { (
response, error) in
print(response)
print(error)
})
I get the following error:
Optional([request-id e70dba3b7ee8f0b9bf6b0aa4b19325f0] API route error - {
".tag" = path;
path = {
".tag" = "not_found";
};
})
But when I try to getthumbnail using this following method I get error .I don't know which url i should return to this function:
DropboxClientsManager.authorizedClient?.files.getThumbnail(path: filename, format: .png, size: .w32h32, overwrite: true, destination: { (url, res) -> URL in
print(url)
print(res)
return url
})
UPDATE:
CAN'T WE GET THUMBNAIL URL FOR DROPBOX IMAGES IN IOS?
Does anyone has the solution ?
Any suggestions??

If you want to get a thumbnail for a file in Dropbox using the API v2 Swift SDK, using one of the getThumbnail methods is the correct approach.
For getThumbnail(path:format:size:overwrite:destination:), note that this will write the thumbnail data to the URL you specify. (I.e., it doesn't provide an Internet-accessible URL where the thumbnail data is hosted.)
The getThumbnail(path:format:size:overwrite:destination:) method is a download-style request, so you should use it as shown under "Download-style request" in the readme, per the "Download to URL" example.
The getThumbnail(path:format:size:) method will return the thumbnail data in memory. You would use it as shown under "Download-style request" in the readme, per the "Download to Data" example.
In either case, note that the path/not_found error you're getting is referring to the path: filename parameter you're supplying. That is, there is nothing found at that path in the Dropbox account. You should specify the remote Dropbox path of the file that you want a thumbnail for.

Related

Images/Videos CDN URL - Detect file type/extension

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');

Swift/iOS Parse image from instagram post

I'm trying to find the way to parse image from instagram post by link with no login in to instagram.
For now I tried to use Kanna but my xpath request dont work.
I have this code:
import Kanna
func getparse(){
if let doc = try? Kanna.HTML(url: URL(string: "https://www.instagram.com/p/CL19xB_M7Wv/")!, encoding: .utf8){
print(doc.title)
for link in doc.xpath(#"//*[#id="react-root"]/section/main/div/div[1]/article/div[2]/div/div/div[1]/div[1]/img/#src"#) {
print(link.text)
}
}
}
How can I parse it correctly and maybe I can use cocoapod or something?
I guess you copied the xpath from chrome. The DOM presented in the browser gets modified, thats why the xpath query fails.
Use a tool like postman to see the actual structure of the response from your request.
Try something like:
doc?.at_xpath(#"/html/head/meta[#property='og:image']"#)?["content"]
The image url is the "content" attribute of the meta tag with the attribute property set to 'og:image'.

How to get users's photo using Microsoft Graph?

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.

How to get share link with dropbox api in Swift?

I want to make an app that lets a user upload a file to dropbox and then get options to share that file. How can I get a dropbox link for a file? It seems like I could use
client.sharing.createSharedLink(path:"/myfile")
but how would I access that data as a String?
Here's a sample of how you could use createSharedLink in SwiftyDropbox to get a shared link to a file, in this example at the path /test.txt.
Dropbox.authorizedClient!.sharing.createSharedLink(path: "/test.txt").response({ response, error in
if let link = response {
print(link.url)
} else {
print(error!)
}
})
Building on #Greg's answer, you can simply replace www.dropbox.com with dl.dropboxusercontent.com and dl=0 with dl=1 to get the direct share link.

Facebook Graph API object_id missing sometimes

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";
}

Resources