01.
<?php
02.
03.
require_once
'fbconfig.php'
;
04.
05.
if
(isset(
$accessToken
)){
06.
if
(isset(
$_SESSION
[
'facebook_access_token'
])){
07.
$fb
->setDefaultAccessToken(
$_SESSION
[
'facebook_access_token'
]);
08.
}
else
{
09.
10.
$_SESSION
[
'facebook_access_token'
] = (string)
$accessToken
;
11.
12.
13.
$oAuth2Client
=
$fb
->getOAuth2Client();
14.
15.
16.
$longLivedAccessToken
=
$oAuth2Client
->getLongLivedAccessToken(
$_SESSION
[
'facebook_access_token'
]);
17.
$_SESSION
[
'facebook_access_token'
] = (string)
$longLivedAccessToken
;
18.
19.
20.
$fb
->setDefaultAccessToken(
$_SESSION
[
'facebook_access_token'
]);
21.
}
22.
23.
24.
$message
=
'Test message from Tachita.ga website'
;
25.
$title
=
'Post From Website'
;
27.
$description
=
'Tachita is a programming blog.'
;
29.
30.
$attachment
=
array
(
31.
'message'
=>
$message
,
32.
'name'
=>
$title
,
33.
'link'
=>
$link
,
34.
'description'
=>
$description
,
35.
'picture'
=>
$picture
,
36.
);
37.
38.
try{
39.
40.
$fb
->post(
'/me/feed'
,
$attachment
,
$accessToken
);
41.
42.
43.
echo
'The post was submitted successfully to Facebook timeline.'
;
44.
}catch(FacebookResponseException
$e
){
45.
echo
'Graph returned an error: '
.
$e
->getMessage();
46.
exit
;
47.
}catch(FacebookSDKException
$e
){
48.
echo
'Facebook SDK returned an error: '
.
$e
->getMessage();
49.
exit
;
50.
}
51.
}
else
{
52.
53.
$fbLoginURL
=
$helper
->getLoginUrl(
$redirectURL
,
$fbPermissions
);
54.
55.
header(
"Location:"
.
$fbLoginURL
);
56.
}