facebook developer posting to facebook but not showing on page - facebook

I am trying to post an image to a facebook page from a PHP script on my server. Everything is authenticating my account with admin rights and I have the permissions of manage_pages, publish_pages and publish_actions.
The image is getting uploaded and I can go to my facebook page and click on Notifications and the post is there, but when I go to Page, Posts, or Images I don't see it. Also, when I look at it in the notification section it is showing it posted by me and as a visitor, it should be showing as posted by the Page. I do have this set as live in Facebook Developer as well.
Can anyone help?
When I run the script I am doing this call to facebook:
$response = $fb->post('/'.$agency_permissions['facebook_page'].'/photos', $data, $agency_permissions['facebook_token']);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
Facebook returns this information: (things labeled '{removed by me}' were removed by me, not returned that way)
Facebook\FacebookResponse Object(
[httpStatusCode:protected] => 200
[headers:protected] => Array
(
[Access-Control-Allow-Origin] => *
[Pragma] => no-cache
[Cache-Control] => private, no-cache, no-store, must-revalidate
[facebook-api-version] => v2.11
[Expires] => Sat, 01 Jan 2000 00:00:00 GMT
[x-fb-rev] => 3698059
[Content-Type] => application/json; charset=UTF-8
[x-fb-trace-id] => H3yiZBKJGQe
[Strict-Transport-Security] => max-age=15552000; preload
[Vary] => Accept-Encoding
[X-FB-Debug] => {removed by me}
[Date] => Tue, 06 Mar 2018 20:43:16 GMT
[Connection] => keep-alive
[Content-Length] => 70
)
[body:protected] => {"id":"1139098132893012","post_id":"335620470144697_1139098132893012"}
[decodedBody:protected] => Array
(
[id] => 1139098132893012
[post_id] => 335620470144697_1139098132893012
)
[request:protected] => Facebook\FacebookRequest Object
(
[app:protected] => Facebook\FacebookApp Object
(
[id:protected] => {removed by me}
[secret:protected] => {removed by me}
)
[accessToken:protected] => {removed by me}
[method:protected] => POST
[endpoint:protected] => /335620470144697/photos
[headers:protected] => Array
(
[Content-Type] => multipart/form-data; boundary=5a9efd619ebd5
)
[params:protected] => Array
(
[message] => test
)
[files:protected] => Array
(
[source] => Facebook\FileUpload\FacebookFile Object
(
[path:protected] => /home/virtual/my_domain/public_html/wp-content///DemoUnitsInternal/7801.jpg
[maxLength:Facebook\FileUpload\FacebookFile:private] => -1
[offset:Facebook\FileUpload\FacebookFile:private] => -1
[stream:protected] => Resource id #26
)
)
[eTag:protected] =>
[graphVersion:protected] => v2.11
)
[thrownException:protected] =>
)

You are using a User Token, that´s why it gets posted as user. Make sure to use a Page Token with manage_pages and publish_pages and it will be posted as Page.

Related

Google Actions: Account linking sends GET request to token URL

I have some problems with the Account Linking for Google Actions:
I have implemented the OAuth2 steps described in the documentation by Google. I have implemented my OAuth2 server and tested it via Postman and am able to get an access token as expected.
If I try to authenticate from the Google Home app by adding the service to my account, I get taken to my authorization form, the authorization works fine and responds with an authorization code to Google's redirect URI as it is supposed to do. However Googles return URI says 'Account linking failed' and then I get a message in the Google Home app : 'Can't update the settings. Check your connection'.
Another strange thing that I've see from my logging of my Token URL script: I can see an incoming GET request from Google to my Token URL instead of a POST request with the required data as mentioned in the Google documentation. So even though the message 'Account linking failed' appears, it seems that Google is calling my token URL, but with a GET instead of a POST.
These are the logs of the requests to the token URL:
REQUEST FROM POSTMAN (testing software) > OK
__SERVER
Array
(
[USER] => www-data
[HOME] => /var/www
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT] => */*
[HTTP_USER_AGENT] => PostmanRuntime/7.6.1
[HTTP_POSTMAN_TOKEN] => f85664e2-7d38-4511-9519-cddda3feec06
[HTTP_CACHE_CONTROL] => no-cache
[HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded
[HTTP_CONTENT_LENGTH] => 145
[HTTP_CONNECTION] => close
[HTTP_HOST] => 127.0.0.1
[REDIRECT_STATUS] => 200
[SERVER_NAME] => _
[SERVER_PORT] => 80
[SERVER_ADDR] => 127.0.0.1
[REMOTE_PORT] => 38622
[REMOTE_ADDR] => 127.0.0.1
[SERVER_SOFTWARE] => nginx/1.12.2
[GATEWAY_INTERFACE] => CGI/1.1
[REQUEST_SCHEME] => http
[SERVER_PROTOCOL] => HTTP/1.0
[DOCUMENT_ROOT] => [******]
[DOCUMENT_URI] => /google/token/index.php
[REQUEST_URI] => /google/token/
[SCRIPT_NAME] => /google/token/index.php
[CONTENT_LENGTH] => 145
[CONTENT_TYPE] => application/x-www-form-urlencoded
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[SCRIPT_FILENAME] => [******]
[FCGI_ROLE] => RESPONDER
[PHP_SELF] => /google/token/index.php
[REQUEST_TIME_FLOAT] => 1553765980.9273
[REQUEST_TIME] => 1553765980
)
__POST
Array
(
[client_id] => [******]
[client_secret] => [******]
[grant_type] => authorization_code
[code] => [******]
)
REQUEST RECEIVED WHEN TESTING WITH GOOGLE HOME APP on smartphone > NOT OK
__SERVER
Array
(
[USER] => www-data
[HOME] => /var/www
[HTTP_ACCEPT_ENCODING] => gzip,deflate,br
[HTTP_USER_AGENT] => OpenAuth
[HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded
[HTTP_CONNECTION] => close
[HTTP_HOST] => 127.0.0.1
[REDIRECT_STATUS] => 200
[SERVER_NAME] => _
[SERVER_PORT] => 80
[SERVER_ADDR] => 127.0.0.1
[REMOTE_PORT] => 46184
[REMOTE_ADDR] => 127.0.0.1
[SERVER_SOFTWARE] => nginx/1.12.2
[GATEWAY_INTERFACE] => CGI/1.1
[REQUEST_SCHEME] => http
[SERVER_PROTOCOL] => HTTP/1.0
[DOCUMENT_ROOT] => [******]
[DOCUMENT_URI] => /google/token/index.php
[REQUEST_URI] => /google/token/
[SCRIPT_NAME] => /google/token/index.php
[CONTENT_LENGTH] =>
[CONTENT_TYPE] => application/x-www-form-urlencoded
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[SCRIPT_FILENAME] => [******]
[FCGI_ROLE] => RESPONDER
[PHP_SELF] => /google/token/index.php
[REQUEST_TIME_FLOAT] => 1553767309.7797
[REQUEST_TIME] => 1553767309
)
__REQUEST
Array
(
)
__POST
Array
(
)
__GET
Array
(
)
-------------------------
__ANSWER
400: invalid grant
Configuration in Actions Console
Problem seemed to be caused by the redirect of / to /index.php without the POST values.
Fixed it by changing my URLs in the Actions Console to /index.php and now the linking works fine.

How to connect to suite CRM REST API using Guzzle

I'm trying to connect to suite CRM REST API using Guzzle
$res = $client->request('GET','http://crm.demo.com/service/v4_1/rest.php/login', [ "auth" => [ 'myadmin', md5('mypswd') ]]);
print_r($res);
The result I'm getting is this
GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
[statusCode:GuzzleHttp\Psr7\Response:private] => 200
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Date] => Array
(
[0] => Mon, 03 Apr 2017 06:26:17 GMT
)
[Content-Type] => Array
(
[0] => text/html; charset=UTF-8
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Connection] => Array
(
[0] => keep-alive
)
[Set-Cookie] => Array
(
[0] => __cfduid=daace974785b1e202e7535232346958d111491200776; expires=Tue, 03-Apr-18 06:26:16 GMT; path=/; domain=.demo.com; HttpOnly
)
[X-Powered-By] => Array
(
[0] => PHP/5.4.16
)
[X-Varnish] => Array
(
[0] => 2592144
)
[Age] => Array
(
[0] => 0
)
[Via] => Array
(
[0] => 1.1 varnish-v4
)
[Server] => Array
(
[0] => cloudflare-nginx
)
[CF-RAY] => Array
(
[0] => 3499f497d6bd17a4-SIN
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[date] => Date
[content-type] => Content-Type
[transfer-encoding] => Transfer-Encoding
[connection] => Connection
[set-cookie] => Set-Cookie
[x-powered-by] => X-Powered-By
[x-varnish] => X-Varnish
[age] => Age
[via] => Via
[server] => Server
[cf-ray] => CF-RAY
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #73
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
Its showing the request was successful but I'm not getting the result. Is it really possible to connect it using Guzzle? Is there any other method to pass the login parameters?
I'm using CodeIgniter 3 and Guzzle to achieve this.
First of all, what's the issue? You code is correct, you get the response.
If you want to explore the response body, just do (string) $res->getBody() or $res->getBody()->getContents() (the body is a stream, as you can in your dump, so to get it as a string you have to do additional actions).
BTW, you are trying to access a site under CloudFlare, and usually it's not possible, because CloudFlare rejects robots. Try to get a different entry point (that is not under CloudFlare protection).

Yii2 Facebook Login issue: Error Validating Client Secret

I'm trying to activate Login via Facebook on my website that is built using Yii2 framework, but the Login is always failing, although the facebook app is authorizing the facebook account used in the login.
The response is always this error:
Request failed with code: 400, message: Error validating client
secret.
Im using yii2's authclient:
return [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'authUrl' => 'facebook.com/dialog/oauth',
//Prod
'clientId' => 'appidhere',
'clientSecret' => 'appsecrethere',
'scope' => 'email, user_friends, public_profile',
.....
The app id and app secret are correct, and the fb app settings are correct as well.
Here's what the request looks like:
yii\httpclient\Request Object ( [_url:yii\httpclient\Request:private]
=> graph.facebook.com/oauth/access_token [_fullUrl:yii\httpclient\Request:private] =>
[_method:yii\httpclient\Request:private] => POST
[_options:yii\httpclient\Request:private] => Array ( [userAgent] => My
Application OAuth 2.0 Client [timeout] => 30 [sslVerifyPeer] => )
[isPrepared:yii\httpclient\Request:private] => [client] =>
yii\httpclient\Client Object ( [baseUrl] => graph.facebook.com
[formatters] => Array ( ) [parsers] => Array ( ) [requestConfig] =>
Array ( ) [responseConfig] => Array ( ) [contentLoggingMaxSize] =>
2000 [_transport:yii\httpclient\Client:private] =>
yii\httpclient\StreamTransport [_events:yii\base\Component:private] =>
Array ( ) [_behaviors:yii\base\Component:private] => )
[_headers:yii\httpclient\Message:private] =>
[_cookies:yii\httpclient\Message:private] =>
[_content:yii\httpclient\Message:private] =>
[_data:yii\httpclient\Message:private] => Array ( [client_id] =>
realappidhere [client_secret] => ​realappsecrethere [code] =>
AQAr0KRC0m4V4lqD8LVcQLNjn76xkZS4skQYAvWf6O_DDeEclaj1LMQm_HoyCoZZezqDn7p9YfJm3qENabU8MKvmH1ffNJotMzgLW2XTbSqQEXlkg_sx7V-ibXRFagpfXTIqCp9Kr54O88bNYGikoOr4TM1ogGjViwS-qKLbvpR_vWgE_FPy9ecpgy86QOITpGrlVJaPAun2bzGaFXmU70Z4Kw3kBWUBPseWc_7ILGymZP-CIbRIIm_YZ8p7t9Vo7jZmieMSd-CMYfG0sgJcBjOgQNvsa3xtHNhPVa5BJNNTy89zulSpTAf3XB6HB_8eql0
[grant_type] => authorization_code [redirect_uri] =>
example.com/site/auth?role=influencer&authclient=facebook )
[_format:yii\httpclient\Message:private] =>
[_events:yii\base\Component:private] => Array ( )
[_behaviors:yii\base\Component:private] => )
And the response is:
yii\httpclient\Response Object ( [client] => yii\httpclient\Client
Object ( [baseUrl] => graph.facebook.com [formatters] => Array
( [urlencoded] => yii\httpclient\UrlEncodedFormatter Object (
[encodingType] => 1 [charset] => ) ) [parsers] => Array ( )
[requestConfig] => Array ( ) [responseConfig] => Array ( )
[contentLoggingMaxSize] => 2000
[_transport:yii\httpclient\Client:private] =>
yii\httpclient\StreamTransport Object (
[_events:yii\base\Component:private] => Array ( )
[_behaviors:yii\base\Component:private] => )
[_events:yii\base\Component:private] => Array ( )
[_behaviors:yii\base\Component:private] => Array ( ) )
[_headers:yii\httpclient\Message:private] => Array ( [0] => HTTP/1.1
400 Bad Request [1] => WWW-Authenticate: OAuth "Facebook Platform"
"invalid_request" "Error validating client secret." [2] =>
Access-Control-Allow-Origin: * [3] => Pragma: no-cache [4] =>
Cache-Control: no-store [5] => facebook-api-version: v2.2 [6] =>
Expires: Sat, 01 Jan 2000 00:00:00 GMT [7] => Content-Type:
text/javascript; charset=UTF-8 [8] => x-fb-trace-id: Ek0PFIJ3B3N [9]
=> x-fb-rev: 2718923 [10] => Vary: Accept-Encoding [11] => X-FB-Debug: yaiIHJkwC4T3UZKrzXOJGJ2DmCTaDr8nIRB3jQnNeEiknx0Ph7i2IR5XmAbxpjM7cBhSEy44AcrglCYEdZEmeg==
[12] => Date: Sun, 04 Dec 2016 11:08:16 GMT [13] => Connection: close
[14] => Content-Length: 115 )
[_cookies:yii\httpclient\Message:private] =>
[_content:yii\httpclient\Message:private] =>
> {"error":{"message":"Error validating client
secret.","type":"OAuthException","code":1,"fbtrace_id":"Ek0PFIJ3B3N"}}
[_data:yii\httpclient\Message:private] =>
[_format:yii\httpclient\Message:private] =>
[_events:yii\base\Component:private] => Array ( )
[_behaviors:yii\base\Component:private] => )
So any idea what's happening in there?
Note: I removed the http and https from the facebook links in the quotes because stackoverflow wouldn't let me post more than 2 links.
Try using Yii2 EAuth extension. This is the best extention which provides social login over 14 diff platforms with the easiest way.
reference url:
https://github.com/Nodge/yii2-eauth
demo url : http://nodge.ru/yii-eauth/demo2/login

Can my facebook app serve a gallery from a different facebook account?

I am trying to serve a Facebook gallery for a client, and due to the server the site is being hosted on, the request needs to be authenticated.
I have set up an app using our company Facebook developer account. Although I have set the domain of the app to that of our client's, the gallery returned in the request is empty.
I am assuming that I will need access to the client's facebook account so I can create an app associated directly with their facebook account - the one where I want the galleries from? EDIT - just thought I'd point out that the client would prefer not to give me their passwords for their facebook account...
Here is the auth code I have used, if anyone will be kind enough to point out any school boy errors I may have made.
$no_albums = 6;
$latest_albums = null;
$user_id = "xxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxx";
$app_token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $user_id
. "&client_secret=" . $app_secret
. "&grant_type=client_credentials"
. "&scope=user_photos";
$response = wp_remote_get($app_token_url);
$access_token = $response['body'];
error_log(print_r($response,true));
$query = 'https://graph.facebook.com/'.$user_id.'/albums?' . $access_token;
$albums = json_decode(file_get_contents('http://graph.facebook.com/'.$user_id.'/albums') );
And this is the response I get ( $albums ) in my error logs:
Array
(
[headers] => Array
(
[access-control-allow-origin] => *
[cache-control] => private, no-cache, no-store, must-revalidate
[content-type] => application/json; charset=UTF-8
[etag] => "1050253aec7b29caff644806927dabfa81406eee"
[expires] => Sat, 01 Jan 2000 00:00:00 GMT
[pragma] => no-cache
[x-fb-rev] => 812093
[x-fb-debug] => 9I0lRzV3GZxrflP/19iBvhly6FLUVI9jCHJAXcw0Dm0=
[date] => Mon, 13 May 2013 10:45:39 GMT
[connection] => close
[content-length] => 11
)
[body] => {"data":[]}
[response] => Array
(
[code] => 200
[message] => OK
)
[cookies] => Array
(
)
[filename] =>
Thanks.
You've got a couple of basic problems here.
First, in your API request, you are looking for albums associated with your APP_ID. There are none. You should be using the client's PAGE_ID or USER_ID in the request to the graph API.
Second, you should be using the Facebook PHP SDK instead of file_get_contents() to make your requests. Especially if this is to be a production environment.
If your clients albums are publicly visible, you may not need to authenticate a user to view them. To know this for sure, you'd need to share your client's Facebook username.

Post custom actions to timeline with publish_stream permission?

I'm trying the following to post custom action on to my timeline. The same effect has been achieved with the Graph API Explorer.
$facebook = new Facebook(array('appId' => '123456789',
'secret' => '123456789',
'cookie' => true));
$access_token = $facebook->getAccessToken();
if($access_token != "")
{
$user = $facebook->getUser();
if($user != 0)
{
$queries = array(array("method" => "POST", "relative_url" => "/me/namespace:action?object=http://www.mysite.com/url/parameters"));
try
{
$postResponseA = $facebook->api("?batch=".json_encode($queries), "POST");
} catch (FacebookApiException $e)
{
echo 'AF error: '.$e;
}
}
}
No errors are thrown. Nothing is ever posted though.
print_r($postResponseA) shows the following:
Array ( [0] => Array ( [code] => 400 [headers] => Array ( [0] => Array ( [name] => Access-Control-Allow-Origin [value] => * ) [1] => Array ( [name] => Cache-Control [value] => no-store ) [2] => Array ( [name] => Connection [value] => close ) [3] => Array ( [name] => Content-Type [value] => text/javascript; charset=UTF-8 ) [4] => Array ( [name] => Expires [value] => Sat, 01 Jan 2000 00:00:00 GMT ) [5] => Array ( [name] => Pragma [value] => no-cache ) [6] => Array ( [name] => WWW-Authenticate [value] => OAuth "Facebook Platform" "invalid_request" "An active access token must be used to query information about the current user." ) ) [body] => {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}} ) )