New Instagram API PHP - php

1) Regarding the new Instagram API, is there another way, than curl, but still in PHP to post a photo (like Facebook API)?
// (For example) :
// Possibility to install Instagram SDK with composer ? And then:
use Instagram\Instagram;
$ insta = new Instagram ([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => '',
]);
$ response = $ insta-> post ('/where', $ data, 'token');
// Like Facebook, you see :-)
2) Is it necessary to need ALL these 3 permissions : manage_pages, instagram_basic and Instagram Public Content Access?

Related

How to automaticaly post on Facebook page with PHP

I'm trying to find solution for automatic posting to my funpage from PHP script, but without user prompt.
My usecase is quite simple - every friday there is event related with my funpage and I would like to post on site wall some information about it (loaded from database) using cron script written in PHP. I would like to use my account to do it.
I found a lot of articles related to autoposting but most of them are stale.
I created new FB application and few lines of code:
$fb = new \Facebook\Facebook([
'app_id' => '1897212530527861',
'app_secret' => $app_secret,
'default_access_token' => $app_access_token,
'default_graph_version' => 'v2.9',
]);
$params = [
'link' => 'www.myurl.com',
'message' => 'Info about the meeting',
];
$response = $fb->post('/my.funpage/feed', $params);
Currently I am reaching error:
The user hasn't authorized the application to perform this action
Might it be related to missing permissions in applciation configuration? I requested for publish_pages and manage_pages, but I can not review it while
there is message.

Facebook Page Tab tabs_added/signed request with PHP

I am revamping the attachment of our Page Tab app using the "Add Page Tab", and am a little unsure about the flow. This is what I'm trying to do:
1) direct our users to the Add Page Tab dialog with our appId (works)
2) our redirect URL is hit with a post that has the "tabs_added" parameter
3) I use this code to try and get information about the FB account that is getting to my app:
$this->fb = new Facebook\Facebook([
'app_id' => <app_id>,
'app_secret' <app secret>,
'default_graph_version' => 'v2.9'
]);
$tabs_added = PARAM('tabs_added');
If I get a 'tabs_added' parameter, I'm assuming that means someone is "attaching" my app to their page, and I want to get information (specifically UID) for their account:
$helper = $this->fb->getPageTabHelper();
$signedRequest = $helper->getSignedRequest();
This call returns nothing
$parsed_signed_request = FacebookSignedRequest::parse_signed_request( $signedRequest, <app secret> );
This call fails because there is no signed request.
What am I missing? I am using v5 of the Facebook PHP API.
thanks

Facebook Graph API: retrieve basic profile information without access_token?

Just that, I'm reading the documentation and it's seems like you can get access to the basic information without auth. But i'm getting an error
the code
$fb = new Facebook([
'app_id' => '...',
'app_secret' => '...',
'default_graph_version' => 'v2.2'
]);
$response = $fb->get('/1000785'); // a valid ramdom user_id
and the response
Type: Facebook\Exceptions\FacebookSDKException
Message: You must provide an access token.
File: ...src/Facebook/FacebookRequest.php
So, should I need to implement the "classic" login anyway?
Ok, just to clarify this issue. It's enough just generating an app access token.
How to generate Facebook App Access Token?
Simply, concatenating app_id and app_secret with a pipe symbol.
$appAccessToken = $config['app_id'] . '|' . $config['app_secret'];
$response = $fb->get('/0123456789', $appAccessToken);
Cheers!

Facebook SDK 5 - reading feeds of a page

I am trying to read the posts of a facebook page, using the actual Facebook SDK 5 for PHP. I have created a facebook app, downloaded and "required" the SDK successfully, but I cannot get the request to run, since it always throws a Invalid OAuth access token signature exception.
The code I have so far:
$fb = new Facebook\Facebook([
'app_id' => $appid,
'app_secret' => $secret,
'default_graph_version' => 'v2.5'
]);
$accesstoken = file_get_contents("https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $appid
. "&client_secret=" . $secret
. "&grant_type=client_credentials" );
//following lines are something I just tried, there have been multiple
//Variantions, none ever worked
$cilent = $fb->getOAuth2Client();
$accessToken = $cilent->getLongLivedAccessToken($accesstoken);
All in all my main issues are:
how to get a valid access token? Since I just want to read public data (feeds of a page), I do not need some special permissons and I am quite confused which on Type of access token I need.
Are there any settings within the facebook app I need to make, or make sure, to get this up and running?
I have googled the web for examples, but I could find examples either using older SDKs (if used at all), or showing how to post data.
I do not have too much experience with that topic and I would appreciate some explanation, or a piece of example.
[UPDATE]
I could manage to get the feeds, some dive through the source was needed.
$fb = new Facebook\Facebook([
'app_id' => 'xxx',
'app_secret' => 'xxx',
'default_graph_version' => 'v2.5'
]);
$req = $fb->get(
'/<page-id>/feed?fields=full_picture,message,name,picture,story,posts&limit=20',
$fb->getApp()->getAccessToken());
In case of success everything one is looking for is included in $res. For sake of simplicity I removed the error handling.
Because everything is desinged to read public data, there is no need for any access-token huzzle, however, retrieving user Data, posting or something else, is not possible with this solution.
Cheers!

Invalid OAuth access token for Facebook

I'm trying to make a simple get request via the Facebook PHP SDK, this way :
$rep = $fb->get('/me',$appsecret_proof);
and here's my configuration :
$config_bis = array(
'app_id' => $config['params_api'][EnvironnementExecution::if_prod() ? 'prod' : 'dev']['config']['appId'],
'app_secret' => $config['params_api'][EnvironnementExecution::id_prod() ? 'prod' : 'dev']['config']['secret'],
'default_access_token' => $config['params_api'][EnvironnementExecution::if_prod() ? 'prod' : 'dev']['access_token'],
);
I stock the Facebook configuration data in a . yml file. The issue is Facebook SDK return me that the access_token is invalid even if I checked it before via the Facebook developer interface.
[2015-10-22 11:26:35] Facebook\Exceptions\FacebookResponseException (pid : 11136) : Invalid OAuth access token.
So any ideas ? Thanks

Categories