nextcloud / contacts

📇 Contacts app for Nextcloud
https://apps.nextcloud.com/apps/contacts
GNU Affero General Public License v3.0
551 stars 168 forks source link

Manually trigger contact photo download from social platforms #2149

Closed schklom closed 3 years ago

schklom commented 3 years ago

Is your feature request related to a problem? Please describe. When setting up new contacts it should be possible to force the download of profile pictures from social networks so there avatar is available immediately without waiting a week.

Describe the solution you'd like A button or occ command is added to force the profile picture download

Additional context Was available but not anymore for some reason. Running Nextcloud 21.0.0.

call-me-matt commented 3 years ago

Hi. Normally this should be possible as described in https://github.com/nextcloud/contacts/issues/1872 . If that's not possible, your admin might have disabled social functions in the groupware settings.

schklom commented 3 years ago

Hi,

Since I am the admin, I can confirm this is enabled both in groupware settings and in the app itself.

After testing more, adding Social Media links makes a menu item appear and load an avatar properly sometimes:

Instagram Error

[index] Error: Exception: Argument 1 passed to OC\Http\Client\Client::get() must be of the type string, null given, called in /var/www/html/custom_apps/contacts/lib/Service/SocialApiService.php on line 212 at <<closure>>

0. /var/www/html/lib/private/AppFramework/App.php line 157
   OC\AppFramework\Http\Dispatcher->dispatch(OCA\Contacts\Con ... {}, "updateContact")
1. /var/www/html/lib/private/Route/Router.php line 302
   OC\AppFramework\App::main("OCA\\Contacts\\ ... r", "updateContact", OC\AppFramework\ ... {}, {network: "insta ... "})
2. /var/www/html/lib/base.php line 993
   OC\Route\Router->match("/apps/contacts/ ... 3")
3. /var/www/html/index.php line 37
   OC::handleRequest()

PUT /apps/contacts/api/v1/social/avatar/instagram/contacts/67ba3e53-e36c-429e-bc7a-bc3b709f2ba3
from <IP> by <USERNAME> at 2021-04-05T15:40:44+02:00

I have checked my pihole logs and Nextcloud has never made a request to Facebook, despite trying Nextclouders, https://www.facebook.com/Nextclouders, and barackobama.

call-me-matt commented 3 years ago

Mastodon is implemented as well. Facebook had to be removed from the list, as they changed their API and do not allow anonymous downloads anymore. For Instagram we have a workaround, but they block requests already after a few downloads. So that might be the reason it's not working for you. I tested here and could not reproduce your error. Your log seems like there is no username given? As you are writing about Facebook-usernames, make sure that you do not mix up Facebook and Instagram profiles.

schklom commented 3 years ago

Too bad for Facebook, that's the most popular one :/

The ones I left unchecked don't even appear in the menu, let alone download an image.

barackobama has a proper Instagram page, but fails.

Here is the raw log (has more info) when triggering an Instagram picture retrieval on barackobama

{
    "reqId": "duDnQOJCgkMkTveeIJpP",
    "level": 3,
    "time": "2021-04-05T18:27:42+02:00",
    "remoteAddr": "REDACTED",
    "user": "REDACTED",
    "app": "index",
    "method": "PUT",
    "url": "/apps/contacts/api/v1/social/avatar/instagram/contacts/67ba3e53-e36c-429e-bc7a-bc3b709f2ba3",
    "message": {
        "Exception": "Exception",
        "Message": "Argument 1 passed to OC\\Http\\Client\\Client::get() must be of the type string, null given, called in /var/www/html/custom_apps/contacts/lib/Service/SocialApiService.php on line 212",
        "Code": 0,
        "Trace": [{
                "file": "/var/www/html/lib/private/AppFramework/App.php",
                "line": 157,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->",
                "args": [{
                        "__class__": "OCA\\Contacts\\Controller\\SocialApiController"
                    }, "updateContact"]
            }, {
                "file": "/var/www/html/lib/private/Route/Router.php",
                "line": 302,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::",
                "args": ["OCA\\Contacts\\Controller\\SocialApiController", "updateContact", {
                        "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
                    }, {
                        "network": "instagram",
                        "addressbookId": "contacts",
                        "contactId": "67ba3e53-e36c-429e-bc7a-bc3b709f2ba3",
                        "_route": "contacts.social_api.update_contact"
                    }
                ]
            }, {
                "file": "/var/www/html/lib/base.php",
                "line": 993,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->",
                "args": ["/apps/contacts/api/v1/social/avatar/instagram/contacts/67ba3e53-e36c-429e-bc7a-bc3b709f2ba3"]
            }, {
                "file": "/var/www/html/index.php",
                "line": 37,
                "function": "handleRequest",
                "class": "OC",
                "type": "::",
                "args": []
            }
        ],
        "File": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "Line": 159,
        "Previous": {
            "Exception": "TypeError",
            "Message": "Argument 1 passed to OC\\Http\\Client\\Client::get() must be of the type string, null given, called in /var/www/html/custom_apps/contacts/lib/Service/SocialApiService.php on line 212",
            "Code": 0,
            "Trace": [{
                    "file": "/var/www/html/custom_apps/contacts/lib/Service/SocialApiService.php",
                    "line": 212,
                    "function": "get",
                    "class": "OC\\Http\\Client\\Client",
                    "type": "->",
                    "args": [null]
                }, {
                    "file": "/var/www/html/custom_apps/contacts/lib/Controller/SocialApiController.php",
                    "line": 141,
                    "function": "updateContact",
                    "class": "OCA\\Contacts\\Service\\SocialApiService",
                    "type": "->",
                    "args": ["*** sensitive parameters replaced ***"]
                }, {
                    "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 218,
                    "function": "updateContact",
                    "class": "OCA\\Contacts\\Controller\\SocialApiController",
                    "type": "->",
                    "args": ["*** sensitive parameters replaced ***"]
                }, {
                    "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 127,
                    "function": "executeController",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args": [{
                            "__class__": "OCA\\Contacts\\Controller\\SocialApiController"
                        }, "updateContact"]
                }, {
                    "file": "/var/www/html/lib/private/AppFramework/App.php",
                    "line": 157,
                    "function": "dispatch",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args": [{
                            "__class__": "OCA\\Contacts\\Controller\\SocialApiController"
                        }, "updateContact"]
                }, {
                    "file": "/var/www/html/lib/private/Route/Router.php",
                    "line": 302,
                    "function": "main",
                    "class": "OC\\AppFramework\\App",
                    "type": "::",
                    "args": ["OCA\\Contacts\\Controller\\SocialApiController", "updateContact", {
                            "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
                        }, {
                            "network": "*** sensitive parameter replaced ***",
                            "addressbookId": "*** sensitive parameter replaced ***",
                            "contactId": "*** sensitive parameter replaced ***",
                            "_route": "contacts.social_api.update_contact"
                        }
                    ]
                }, {
                    "file": "/var/www/html/lib/base.php",
                    "line": 993,
                    "function": "match",
                    "class": "OC\\Route\\Router",
                    "type": "->",
                    "args": ["/apps/contacts/api/v1/social/avatar/instagram/contacts/67ba3e53-e36c-429e-bc7a-bc3b709f2ba3"]
                }, {
                    "file": "/var/www/html/index.php",
                    "line": 37,
                    "function": "handleRequest",
                    "class": "OC",
                    "type": "::",
                    "args": []
                }
            ],
            "File": "/var/www/html/lib/private/Http/Client/Client.php",
            "Line": 234
        },
        "CustomMessage": "--"
    },
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0",
    "version": "21.0.0.18",
    "id": "606b3a7f52e9f"
}

Hopefully that tells you the exact problem :)

call-me-matt commented 3 years ago

Yes, I agree - it is very annoying. It worked so nicely until they decided to renew their API. The only way to tackle this would be to ask users for their facebook/instagram login, but that contradicts the idea of a nextcloud in my point of view. I am sorry, but I have no idea on how to solve this issue. Concerning Mastodon, can you verify it is not showing up for you? Are you using contacts version 3.5+ ?

schklom commented 3 years ago

Contacts version 3.5.1

The only way to tackle this would be to ask users for their facebook/instagram login, but that contradicts the idea of a nextcloud in my point of view.

I agree about it being against the idea of Nextcloud, but if that's the only problem, then why not make the login optional and opt-in ? Only the people who want to use it will be able to.

Concerning Mastodon, can you verify it is not showing up for you?

I have no clue what I did, but now Mastodon is showing and working properly :D I'm updating the previous comment.

I think I should leave this issue open until Facebook works, but go ahead and close it if you feel it's redundant :)

call-me-matt commented 3 years ago

At least Mastodon is not letting us down!

For facebook I'll call it a duplicate of https://github.com/nextcloud/contacts/issues/1891 so it won't be forgotten. And believe me, I would be very happy if there could be a fix, too!

schklom commented 3 years ago

Is the Facebook/Instagram issue happening with LinkedIn too ? Because it doesn't appear on the menu as well, and was my backup plan after Facebook and Instagram :P

call-me-matt commented 3 years ago

No, LinkedIn seemed very closed from the beginning on - I did not find any API or access method without account, so I did not event try.

nathan-skynet commented 3 years ago

I have the same error in the Nextcloud server log files as @schklom.

I'm not an expert on this, I'm more of a JavaScript guy, but it seems to me that you can try to adapt "Instagram-php-scraper", the getAccount function does return the Instagram profile photo information.

Translated with www.DeepL.com/Translator

call-me-matt commented 3 years ago

That looks promising. Unfortunately I did not succeed in trying it out: PHP Fatal error: Uncaught InstagramScraper\\Exception\\InstagramException: Response code is 302. Body: Something went wrong. Please report issue. When looking at the open issues, it seems that scraper has the same problems we are facing.

nathan-skynet commented 3 years ago

I'm going to try another approach, if on my end I create a server with Instagram / Facebook credentials and create some sort of api. Can we integrate it in the application or not?

If I understand correctly the problem is that we can't make a request if we are not logged in directly, right?

call-me-matt commented 3 years ago

I'm going to try another approach, if on my end I create a server with Instagram / Facebook credentials and create some sort of api. Can we integrate it in the application or not?

Had the same idea in the very beginning when I wanted to use avatars.io But the idea was rejected. (avatars.io seems to be offline now, by the way)

nathan-skynet commented 3 years ago

I'm going to try another approach, if on my end I create a server with Instagram / Facebook credentials and create some sort of api. Can we integrate it in the application or not?

Had the same idea in the very beginning when I wanted to use avatars.io But the idea was rejected. (avatars.io seems to be offline now, by the way)

Then, I have no more ideas. If in Nextcloud, in the admin settings, you add an option to put your Instagram or Facebook username and password, would that be more legal?

call-me-matt commented 3 years ago

Yes, I think this should work, see https://github.com/nextcloud/contacts/issues/1891#issuecomment-717768024

nathan-skynet commented 3 years ago

Yes, I think this should work, see #1891 (comment)

Any idea where to start?

call-me-matt commented 3 years ago

I don't think it's an admin-, but more a user setting. But no idea how to integrate this into the small user settings area. An alternative could be a dedicated section in the settings. But this would make it three different places where groupware settings can be modified (cogwheel-setting in the address book, admin settings and the new user settings section in the settings). maybe @nextcloud/designers can give a hint how it should integrate?