muesli / beehive

A flexible event/agent & automation system with lots of bees 🐝
GNU Affero General Public License v3.0
6.32k stars 325 forks source link

Allow posting content to Facebook Pages (#353) #354

Closed pbek closed 4 years ago

pbek commented 4 years ago

Implements #353

pbek commented 4 years ago

Needs more work, because I used mod.session.Post and that seems to also validate the access token (which expires after one hour). So I'll have to do the POST by hand. 😬

2020-11-02T19:02:13.865106254Z INFO[2111] [Facebook 3]: Attempting to post "New release of QOwnNotes: v20.11.1: https://www.qownnotes.org/changelog.html#_20-11-1 #QOwnNotes #ownCloud #Nextcloud" to Facebook Page "1079606388736701" 
2020-11-02T19:02:13.911774545Z ERRO[2111] [Facebook 3]: Error: [message:Error validating access token: Session has expired on Monday, 02-Nov-20 10:00:00 PST. The current time is Monday, 02-Nov-20 11:02:27 PST.] [type:OAuthException] [code:190] [subcode:463] 
pbek commented 4 years ago

And the token is not a permanent one...

1) We currently only have a Short-lived User Access Token that is valid for one hour (user interaction required). 2) You need 1) to get a Long-lived User Access Token (valid 60 days), request can be made in the background 3) You need 2) to get a Permanent token, request can be made in the background

pbek commented 4 years ago

I'll have to implement https://medium.com/@blienart/get-a-permanent-facebook-page-access-token-a96470dc03ca

pbek commented 4 years ago

Needs more work, because I used mod.session.Post and that seems to also validate the access token (which expires after one hour). So I'll have to do the POST by hand. grimacing

2020-11-02T19:02:13.865106254Z INFO[2111] [Facebook 3]: Attempting to post "New release of QOwnNotes: v20.11.1: https://www.qownnotes.org/changelog.html#_20-11-1 #QOwnNotes #ownCloud #Nextcloud" to Facebook Page "1079606388736701" 
2020-11-02T19:02:13.911774545Z ERRO[2111] [Facebook 3]: Error: [message:Error validating access token: Session has expired on Monday, 02-Nov-20 10:00:00 PST. The current time is Monday, 02-Nov-20 11:02:27 PST.] [type:OAuthException] [code:190] [subcode:463] 

I fixed that one. It all works well now with an expired user access token, but manually getting a permanent page token is still inconvenient.

pbek commented 4 years ago

Automatic permanent page access token generating and storing are working now!

The pull request is now ready for inspection and merging, @muesli!

pbek commented 4 years ago

@muesli, I improved the error handling and created an inline struct. Thank you for the helpful feedback... New things I learned. 😁

muesli commented 4 years ago

Thank you!

pbek commented 4 years ago

Thank you for all your feedback!