get high quality facebook profile picture with cordova plugin - facebook

I'm developing ionic 2 app. I'm trying to get high quality image and then resize it to avatar photo.
My code:
_FBUserProfile() {
return new Promise((resolve, reject) => {
Facebook.api('me?fields=id,name,email,first_name,last_name,picture.width(600).height(600).as(picture_small),picture.width(360).height(360).as(picture_large)', [])
.then((profileData) => {
console.log(JSON.stringify(profileData));
return resolve(profileData);
}, (err) => {
console.log(JSON.stringify(err));
return reject(err);
});
});
}
But, the photo isn't good quality, since I guess I did something wrong with the resize in this line:
picture.width(600).height(600).as(picture_small),picture.width(360).height(360).as(picture_large)', [])
How can I get good quality of the photo?

If you want to get the public profile picture of the user and you know the user id from the api call then use this url for picture
profileData.picture="https://graph.facebook.com/"+profileData.id+"/picture?width=1024&height=1024";

You've got a couple of solutions, like using type large
id,name,email,first_name,last_name,picture.type(large)
As explained here: https://developers.facebook.com/docs/graph-api/reference/user/picture/

Related

FILE_URI path for Camera not working on IONIC 4

When using the Cameara to take a picture with destinationType: this.camera.DestinationType.FILE_URI, the resulting URL will not work to display the image. For example, when attempting to take a photo like this:
this.camera.getPicture(options).then((url) => {
// Load Image
this.imagePath = url;
}, (err) => {
console.log(err);
});
Attempting to display it as <img [src]="imagePath" > will result in an error (file not found).
The problem here is that the URL is in the file:///storage... path instead of the correct one based on localhost.
In previous versions of Ionic, this would be solved by using normalizeURL. This will not work on Ionic 4 (or at least I could not make it work).
To solve this issue, you will need to use convertFileSrc():
import {WebView} from '#ionic-native/ionic-webview/ngx';
...
this.camera.getPicture(options).then((url) => {
// Load Image
this.imagePath = this.webview.convertFileSrc(url);
}, (err) => {
console.log(err);
});
Now the image URL will be in the appropriate http://localhost:8080/_file_/storage... format and will load correctly.
See WKWebView - Ionic Docs for more information.
In my case, the following code works with me
const downloadFileURL = 'file:///...';
// Convert a `file://` URL to a URL that is compatible with the local web server in the Web View plugin.
const displayedImg = (<any>window).Ionic.WebView.convertFileSrc(downloadFileURL);
In case some gots here looking for the answer on ionic4, check this out
"Not allowed to load local resource" for Local image from Remote page in PhoneGap Build
and look for the answer from #Alok Singh that's how I got it working on ionic4 and even works with livereload
UPDATE december 2021:
You have to install the new Ionic Webview
RUN:
ionic cordova plugin add cordova-plugin-ionic-webview
npm install #awesome-cordova-plugins/ionic-webview
Import it in app.module and your page where you wanna use it:
import { WebView } from '#awesome-cordova-plugins/ionic-webview/ngx';
image = "";
constructor(private webview: WebView){}
Then this will work:
this.camera.getPicture(options).then((imageData) => {
this.image = this.webview.convertFileSrc(imageData)
}, (err) => {
// Handle error
});
And show it in the HTML page:
<img [src]="image" alt="">

How to intergrate medium-editor-insert-plugin with laravel 5.5

I have been trying to upload images to my Medium-editor using the Medium-editor-insert-plugin with Laravel5.5 for days without success.
To me it seems like the image is to passing to the sever and I don't know why.
I am using the latest release version of medium-editor-insert-plugin.
here is my javascript code to initiate the medium-insert-plugin:
$(function () {
$('.body-editable').mediumInsert({
editor: bodyEditor,
addons: {
images: {
fileUploadOptions: {
url: 'upload',
}
}
}
});
});
and the route to send the request to the back-end look like this.
// upload image route for MediumInsert plugin
Route::post('upload', 'PostsController#upload');
and inside my controller i am return all the request data like this:
public function upload(Request $request)
{
return array('data:'=> $request->all());
$upload_handler = new UploadHandler(array(
//'upload_dir' => public_path().'uploads/',
'upload_dir' => 'uploads/',
'upload_url' => 'posts/upload/',
));
}
but after use the plugin to insert an image to the editor i am get this error
But in my network response i am getting this.
{"data:":{"files":[{}]}}
Please can someone tell me what to do? have been trying to edited the plugin itself but no way till now.
You should probably return only the data object property.
{"files":[{}]}

Jquery Mobile flicker/white screen in iPhone

After detail search and googling I finally decide to put my question.
In my JQM web app there are total 4 pages. 2 of them are dynamically populated via Ajax. I have used
$.extend($.mobile, {
defaultPageTransition: 'none'
});
My dynamically populated function is
$.get_detail= function(){
$.ajax({
url: "mypage.cfm",
data: data,
timeout:5000,
cache:false,
type:'GET',
dataType:"html",
success: function(data3) {
//$('#filldiv').empty();
$("#filldiv").html(data3);
$.mobile.changePage('#detailpage');
},
error: function(statusCode, errorThrown)
{
if (statusCode.status == 0)
alert("you are offline");
else
alert("Please try again.");
}
});
}
When I change page flash white screen just like flicer happened but when there is no data fill in div then there is no flicker. I have noticed that, if there is no screen size change then every thing is okay and if screen size change by filling the dynamic content flicker happen
Please help me out to solve this issue. Thank you
Here's what I'm using to disable default transitions:
$(document).on( "mobileinit", function() {
$.mobile.defaultPageTransition = 'none';
});
The newest version 1.4, is also supposed to help with better transitions.

Getting full-size profile picture

Is there anyway to get the full-size profile picture using any facebook api?
http://graph.facebook.com/{ID}/picture?type=large is way to small.
Thanks :)
Set either the width or height to some arbitrarily large number:
https://graph.facebook.com/username_or_id/picture?width=9999
If the width and height are the same number, the photo is cropped to a square.
I think I use the simplest method to get the full profile picture. You can get full profile picture or you can set the profile picture dimension yourself:
$facebook->api(me?fields=picture.width(800).height(800))
You can set width and height as per your need. Though Facebook doesn't return the exact size asked for, It returns the closest dimension picture available with them.
found a way:
$albums = $facebook->api('/' . $user_id . '/albums');
foreach($albums['data'] as $album){
if ($album['name'] == "Profile Pictures"){
$photos = $facebook->api('/' . $album['id'] . '/photos');
$profile_pic = $photos['data'][0]['source'];
break;
}
}
As noted above, it appears that the cover photo of the profile album is a hi-res profile picture. I would check for the album type of "profile" rather than the name though, as the name may not be consistent across different languages, but the type should be.
To reduce the number of requests / parsing, you can use this fql:
"select cover_object_id from album where type='profile' and owner = user_id"
And then you can construct the image url with:
"https://graph.facebook.com/" + cover_object_id + "/picture&type=normal&access_token=" + access_token
Looks like there is no "large" type for this image, but the "normal" one is still quite large.
As noted above, this photo may be less accessible than the public profile picture. You need the user_photos or friend_photos permission to access it.
With Javascript you can get full size profile images like this
pass your accessToken to the getface() function from your FB.init call
function getface(accessToken){
FB.api('/me/friends', function (response) {
for (id in response.data) {
var homie=response.data[id].id
FB.api(homie+'/albums?access_token='+accessToken, function (aresponse) {
for (album in aresponse.data) {
if (aresponse.data[album].name == "Profile Pictures") {
FB.api(aresponse.data[album].id + "/photos", function(aresponse) {
console.log(aresponse.data[0].images[0].source);
});
}
}
});
}
});
}
For Angular:
getUserPicture(userId) {
FB.api('/' + userId, {fields: 'picture.width(800).height(800)'}, function(response) {
console.log('getUserPicture',response);
});
}
Profile pictures are scaled down to 125x125 on the facebook sever when they're uploaded, so as far as I know you can't get pictures bigger than that. How big is the picture you're getting?

accessing iPhone compass with JavaScript

Know if it's possible to access the iPhone compass in Safari using JavaScript? I see how the GPS can be accessed, but I can't figure out the compass.
On iOS, you can retrieve the compass value like this.
window.addEventListener('deviceorientation', function(e) {
console.log( e.webkitCompassHeading );
}, false);
For more informations, read the Apple DeviceOrientationEvent documentation.
Hope this helps.
You cannot access that information via javascript, unless you're using something like iPhoneGap
At the time this was true, in iOS 5 you can use the compass heading in JS. https://developer.apple.com/documentation/webkitjs/deviceorientationevent/1804777-webkitcompassheading
For Android it works auto, for iOS it needs to be clicked to start it.
Here's a part of code you can use for that
startBtn.addEventListener("click", startCompass);
function startCompass() {
if (isIOS) {
DeviceOrientationEvent.requestPermission()
.then((response) => {
if (response === "granted") {
window.addEventListener("deviceorientation", handler, true);
} else {
alert("has to be allowed!");
}
})
.catch(() => alert("not supported"));
} else {
window.addEventListener("deviceorientationabsolute", handler, true);
}
}
function handler(e) {
const degree = e.webkitCompassHeading || Math.abs(e.alpha - 360);
}
Full tutorial is here, try demo also
https://dev.to/orkhanjafarovr/real-compass-on-mobile-browsers-with-javascript-3emi
I advise you to use LeafletJS with this plugin
https://github.com/stefanocudini/leaflet-compass
very simple to use with events and methods.
You can try a demo here:
https://opengeo.tech/maps/leaflet-compass/