Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Facebook - Udostępnianie treści na stronie przez skrypt cron'a
Valantir
post 4.06.2015, 14:19:07
Post #1





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 6.09.2011
Skąd: Olsztyn

Ostrzeżenie: (0%)
-----


Witam serdecznie, może ktoś z Was wie w jaki sposób wykonywać udostępnianie na swojej stronie na facebooku treści z automatu bez konieczności "ręcznego" logowania się na fb? Treści będą udostępniane przez skrypt podpięty pod crona.

Ten post edytował Valantir 4.06.2015, 14:19:43


--------------------
Pomogłem? Kliknij "Pomógł".
Go to the top of the page
+Quote Post
Xelah
post 5.06.2015, 07:18:37
Post #2





Grupa: Zarejestrowani
Postów: 139
Pomógł: 24
Dołączył: 12.05.2013
Skąd: Hamburg

Ostrzeżenie: (0%)
-----


https://developers.facebook.com/docs/graph-api
Go to the top of the page
+Quote Post
warder
post 4.09.2016, 12:16:37
Post #3





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 12.12.2010

Ostrzeżenie: (0%)
-----


Czy ktoś zna rozwiązanie na powyższy problem? Jak z poziomu skryptu PHP pisać post na tablicy strony facebooka (chodzi o fanpage).

Próbowałem wykorzystać ten skrypt: https://developers.facebook.com/docs/php/ho...mple_post_links
  1. $fb = new Facebook\Facebook([
  2. 'app_id' => '{app-id}',
  3. 'app_secret' => '{app-secret}',
  4. 'default_graph_version' => 'v2.2',
  5. ]);
  6.  
  7. $linkData = [
  8. 'link' => 'http://www.example.com',
  9. 'message' => 'User provided message',
  10. ];
  11.  
  12. try {
  13. // Returns a `Facebook\FacebookResponse` object
  14. $response = $fb->post('/me/feed', $linkData, '{access-token}');
  15. } catch(Facebook\Exceptions\FacebookResponseException $e) {
  16. echo 'Graph returned an error: ' . $e->getMessage();
  17. } catch(Facebook\Exceptions\FacebookSDKException $e) {
  18. echo 'Facebook SDK returned an error: ' . $e->getMessage();
  19. }
  20.  
  21. $graphNode = $response->getGraphNode();
  22.  
  23. echo 'Posted with id: ' . $graphNode['id'];



W linijce:
  1. // Returns a `Facebook\FacebookResponse` object
  2. $response = $fb->post('/ID_MOJEJ_STRONY_NA_FB/feed', $linkData, $access_token);


jest 'access token' który sprawia mi największy problem. Otóż, jeśli na stronie https://developers.facebook.com/tools/explo...290064954686317 wygeneruje sobie access token z potrzebnymi uprawnieniami, to wszystko działa, post publikuje się na tablicy strony z poziomu aplikacji, ale acccess token działa jedynie przez najbliższe 2 godziny.. sad.gif


Podążając dalej za instrukcjami z facebooka, użyłem:
Kod
$access_token = $fb->getApp()->getAccessToken();

Jednak wtedy, dostaje komunikat:

Graph returned an error: (#200) The user hasn't authorized the application to perform this action
Go to the top of the page
+Quote Post
trueblue
post 4.09.2016, 13:28:02
Post #4





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Musisz wygenerować sobie "never-expire" token.


--------------------
Go to the top of the page
+Quote Post
warder
post 4.09.2016, 17:17:48
Post #5





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 12.12.2010

Ostrzeżenie: (0%)
-----


W jaki sposób to zrobić, by mogło to działać z poziomu skryptu php?
Go to the top of the page
+Quote Post
Aqu
post 5.09.2016, 19:11:53
Post #6





Grupa: Zarejestrowani
Postów: 279
Pomógł: 58
Dołączył: 14.07.2012

Ostrzeżenie: (0%)
-----


How to generate a long-lived token:
1. Start with a short-lived token generated on a client and ship it back to your server.
2. Use the user token, your app ID and app secret to make the following call from your server to Facebook's servers:

  1. GET /oauth/access_token?
  2. grant_type=fb_exchange_token&
  3. client_id={app-id}&
  4. client_secret={app-secret}&
  5. fb_exchange_token={short-lived-token}


https://developers.facebook.com/docs/facebo...n-and-extension
Go to the top of the page
+Quote Post
trueblue
post 5.09.2016, 19:26:54
Post #7





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Long-lived token ma czas życia 60 dni.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 1.05.2025 - 06:19