-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect image from Facebook #1891
Comments
oh no. you are right, the facebook API seems not to work anymore:-/ What a pity!
Lets keep our fingers crossed they dont do the same with Insta. |
Have users generate an access token and store it so it can be used in API calls. |
Maybe we can ask to @eneiluj which I think developped the integration apps. And I don’t know a lot, but on Android I can use CoSy for Facebook, which can sync profile pictures after I haved logged in on Facebook. |
@call-me-matt, what we can do is fetch the raw page of the profile (https://facebook.com/Nextclouders), and fetch the meta image in the source |
I think this works only for public profiles and pages. Other profiles do work also, but only very limited and low-res. After a couple of requests, the login-page is shown instead.
I noticed they also have a delay of several seconds between each request. |
Yes, but only for importing friends, not for synchronisation, as it appears : https://mflisar.github.io/cosy/why-is-import-slow.html |
Still, there seems to be a pretty low limit. Accessing profile pages without being logged in only works a few times until you keep being redirected to the login page. Try it out by replacing your file: apps/contacts/lib/Service/Social/FacebookProvider.php<?php
namespace OCA\Contacts\Service\Social;
use OCP\Http\Client\IClientService;
class FacebookProvider implements ISocialProvider {
/** @var IClientService */
private $httpClient;
public function __construct(IClientService $httpClient) {
$this->httpClient = $httpClient->NewClient();
}
/**
* Returns the profile-id
*
* @param {string} the value from the contact's x-socialprofile
*
* @return string
*/
public function cleanupId(string $candidate):string {
try {
if (strpos($candidate, 'http') !== 0) {
$candidate = 'https://www.facebook.com/' . $candidate;
}
} catch (Exception $e) {
$candidate = null;
}
return $candidate;
}
/**
* Returns the profile-picture url
*
* @param {string} profileId the profile-id
*
* @return string|null
*/
public function getImageUrl(string $profileUrl):?string {
try {
$result = $this->httpClient->get($profileUrl);
$htmlResult = $result->getBody();
$avatar = '/profilePicThumb">[ \n\t]*<img[^>]+src="(http[^"]+)/';
if (preg_match($avatar, $htmlResult, $matches)) {
return $matches[1];
}
// keyword not found, maybe page changed?
return null;
} catch (Exception $e) {
return null;
}
}
} |
I tried but it cannot fetch any tried profile picture... But the default Facebook picture doesn’t update. |
i haven't dug into the logs, but i'm also seeing a http 400 on any attempt to download an avatar from instagram |
It seems facebook profiles are accessible again without login. Not per API, but still. |
Can you write what your regex looks like, and give a few strings it should match ? |
Hi schklom. Thank you for offering help! This was my attempt to fetch the image from facebook: $result = $this->httpClient->get($profileUrl);
$htmlResult = $result->getBody();
$avatar = '/meta property="og:image" content="(http[^"]+)/';
if (preg_match($avatar, $htmlResult, $matches)) {
return html_entity_decode($matches[1]);
} But the page has changed and the profile picture is not tagged with og:image anymore. Take a look at the facebook page's source code (most comfortable with the "inspector" tool from your browser). |
On Nextclouders.de's page + 2 friends' pages, I found that searching (on the Inspector tool) for It seems these urls are only valid for ~30s, and I have no clue if they appear with PHP. The one that exists contains the profile picture when there is one. If they do, I think this regex should work For the 2nd, try Maybe remove the Hopefully it helps :) |
Thank you for your work. Now we need to figure out how to load the page with php, as the request from my code seems not to load the complete page. |
This is strange. A basic After searching a little it seems others had success simulating a browser via Here is the link of a guy who had some success if it helps https://stackoverflow.com/a/55829622 In order to check which headers to send, you can check the ones your browser sends when you connect to facebook. |
Well, it works for public pages (like nextclouders) but it does not work for profiles (try it out for https://www.facebook.com/zuck). It seems like a basic page is loaded and only after a moment the actual content is reloaded. Any idea how to fetch that with php? |
@call-me-matt This definitely requires executing some JavaScript that is loaded on the actual profile page. Programs like HtmlUnit exist that can facilitate this, but HtmlUnit in particular would require a Java runtime on the server, which PHP can then hook into. I don't know of any PHP library or anything that allows this to be done all in PHP instead. Probably best just to have the Nextcloud user log in / connect to Facebook, then we have a Facebook Client Access Token that can be used to query the Facebook Graph API and get the image. |
Hi @call-me-matt, Following on this thread. Was there any developments on this matter eventually. To be honest, I get the feeling that this profile image updating concept kinda died, based on the fact that there was no other threads on this and Google+ is still listed as a social network. |
@call-me-matt Aaaaa thank you for the clarification. Honestly, most people have Facebook. As the saying goes "everyone and their dog is on Facebook". So I really would like to see renewed development in a Facebook Integration plugin. Unfortunately I can't give much development help (as I lack the skillset) but I would be more then happy to do any testing and QAs |
https://developers.facebook.com/docs/graph-api/reference/user/picture/
I'll close this as not planned for now, Let me know if there's a way to get the image from facebook that I missed |
Steps to reproduce
Expected behaviour
Have the image of the profil of the url
Actual behaviour
The new image is the the default avatar of Facebook (so not exactly an image). I have tried with different profiles, it’s always the same. And I tried with Instagram which works normaly.
When I try to get from Facebook for first time

When I try to update from Facebook an already updated Facebook image

Server configuration detail
Operating system: Linux 5.8.0-0.bpo.2-amd64 #1 SMP Debian 5.8.10-1~bpo10+1 (2020-09-26) x86_64
Webserver: nginx/1.14.2 (fpm-fcgi)
Database: mysql 10.3.25
PHP version:
7.3.23-4+0
20201018.71+debian101.gbpfc8934Modules loaded: Core, date, libxml, openssl, pcre, zlib, filter, hash, Reflection, SPL, sodium, session, standard, cgi-fcgi, mysqlnd, PDO, xml, apcu, bcmath, bz2, calendar, ctype, curl, dom, mbstring, fileinfo, ftp, gd, gettext, gmp, iconv, igbinary, imagick, imap, intl, json, ldap, exif, mysqli, pdlib, pdo_mysql, apc, posix, readline, redis, shmop, SimpleXML, smbclient, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xmlreader, xmlwriter, xsl, zip, Phar, libsmbclient, Zend OPcache
Nextcloud version: 20.0.1 - 20.0.1.1
Updated from an older Nextcloud/ownCloud or fresh install: Updated from 19.04
Where did you install Nextcloud from: Yunohost (https://github.com/yunohost-apps/nextcloud_ynh)
Signing status
Integrity checker has been disabled. Integrity cannot be verified.
List of activated apps
Configuration (config/config.php)
Are you using external storage, if yes which one: Local
Are you using encryption:
Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/...
LDAP configuration (delete this par if not used)
Client configuration
Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0
Operating system:
Logs
Web server error log
Nextcloud log
Browser log
Insert your browser log here, this could for example include:
The text was updated successfully, but these errors were encountered: