$facebook = new Facebook(array(
'appId' => '<key>',
'secret' => '<secret code>',
'cookie' => true
));
print_r($facebook);die;
Output of this is
Facebook Object
(
[appId:protected] => <key>
[apiSecret:protected] => <secret code>
[session:protected] =>
[signedRequest:protected] =>
[sessionLoaded:protected] =>
[cookieSupport:protected] => 1
[baseDomain:protected] =>
[fileUploadSupport:protected] =>
)
This problems occur in the end of October only as before that it always prints information of session. Then I call link https://api.facebook.com/method/photos.getAlbums?uid='.$session['uid'].'&access_token='.$session['access_token'] and used to get list of albums.
This works fine for more than 8 months and suddenly from last month it stopped working.
We had some troubles on our Facebook API a couple months ago too.
Facebook has deprecated the REST API, which you are using. It is very possible the feature you're trying to access has changed and is no longer supported.
Source: http://developers.facebook.com/blog/post/616/
Switch to the new OAuth2.0 API to restore your features and future proof your application for awhile..
Here's the link to the new API documentation:
http://developers.facebook.com/docs/reference/api
Oh, and in the future... Be sure to remove any API keys and secret codes from your posts. These would potentially allow someone else to use your credentials mischievously.
Related
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.
I've just gotten started with the latest facebook SDK (5.0). It's been a number of years since I last used it, and there's one thing I can't seem to get around...
Following the example code they have here: https://developers.facebook.com/docs/php/howto/example_facebook_login/5.0.0
I'm able to get a perfectly working login. My problem is, how do you keep this login alive on the next page load when you aren't being redirected back from facebook?
you used to be able to store the user access token, then reuse that token to keep the session authenticated. In version 5.0 of the SDK, I'm not seeing a way to do that, and i'm pretty lost how you remain logged in.
I wouldn't be asking this here, but I've been looking for a couple days now and have found an abundance of articles using older code that doesn't line up with the current 5.0 sdk I'm trying to use. I'm guessing this is something small that I've been missing or over looking, but I'd love any information you guys can give me.
At the end of the exemple in the link you give, there is this line:
$_SESSION['fb_access_token'] = (string) $accessToken;, so the access token is stored in the PHP session and then accessible from page to page.
You can also store it in your database as a field in your users table.
Below great upgrade guides:
Facebook PHP SDK v3.x to v5.x
Facebook PHP SDK v4.0 to v5
I know it's too late but I just wanted to leave an answer as a record. From FB official doc:
Configuration options
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_access_token' => '{access-token}',
'enable_beta_mode' => true,
'default_graph_version' => 'v2.3',
'http_client_handler' => 'guzzle',
'persistent_data_handler' => 'memory',
'url_detection_handler' => new MyUrlDetectionHandler(),
'pseudo_random_string_generator' => new MyPseudoRandomStringGenerator(),
]);
If you don't provide a default_access_token in the configuration
options, or you wish to use a different access token than the default,
you can explicitly pass the access token as an argument to the get(),
post(), and delete() methods.
$res = $fb->get('/me', '{access-token}');
$res = $fb->post('/me/feed', ['foo' => 'bar'], '{access-token}');
$res = $fb->delete('/{node-id}', '{access-token}');
I am trying to write a PHP script that will allow me to do two things:
Allow users to use their Hotmail (I think its called 'Live' now?) account to authenticate themselves to a website
Retrieve an authenticated users contact list from Hotmail.
I have trawled the internet for the past 6 hours, looking for at least a working example that I can modify/extend to do the above two things. There are several dozens similar questions asked here on SO for example - NONE of the proffered answers work any more (admittedly, some of the questions were a few years old).
I tried the Microsoft site and downloaded the latest version of their API which seems to evolve at a rather alarming rate. I finally managed to track down an API which has not been deprecated (yet?).
I followed the instructions and when I attempted to authenticate, I was rewarded with the following mesage, for my efforts:
We're unable to complete your request
Windows Live ID is experiencing technical difficulties. Please try again later.
I immediately tried the online version of the demo and perhaps unsurprisingly, that worked like a charm.
As an aside, I managed to implement the same functionality for Yahoo and GMail, using their OPEN APIs, under an hour each. Now, it is possible that my unmitigated hatred of all things proprietary (sorry make that Microsoft), is causing me to lose the plot a little here.
Has anyone ACTUALLY (in 2012) managed to get a working sample in PHP that allows:
Hotmail (live?) user authentication
Hotmail user contact email retrieval
If you have, a code snippet, or a link to where I can find such a snippet would be very useful, as I have so far, wasted a whole afternoon trying to work the Microsoft Live API via PHP.
PS: No, I'm not interested in OpenInviter, its broken.
i wrote my own oauth library based around a single array for each service provider. this array contains all of the data required to perform authentication and retrieve user data. the array i use for msdn (ie. hotmail, outlook, xbox, msn) is:
$msdn = array
(
'oauth_version' => '2',
'oauth_method' => 'GET',
'redirect_user_params' => array
(
'url' => 'https://oauth.live.com/authorize',
'response_type' => 'code',
'http_params' => array
(
'url',
'client_id',
'redirect_uri',
'response_type',
'scope',
'state'
)
),
'obtain_access_token_params' => array
(
'url' => 'https://oauth.live.com/token',
'grant_type' => 'authorization_code',
'http_params' => array
(
'url',
'client_id',
'client_secret',
'code',
'grant_type',
'redirect_uri',
'scope'
)
),
'scope' => 'wl.signin wl.basic',
'obtain_user_data_params' => array
(
'url' => 'https://apis.live.net/v5.0/me',
'http_params' => array
(
'url',
'access_token',
'scope'
)
),
'client_id' => 'xxxxx', // = oauth_consumer_key in oauth 1.0 lingo
'client_secret' => 'xxxxxxxxxxxxxxx',
'readme_url' => 'http://msdn.microsoft.com/en-us/library/live/hh243647.aspx'
);
the parameters for each of the three oauth stages (ie "redirect user", "obtain access token" and "obtain user data") are in the http_params arrays. in the case of msdn these parameters end up in the query query string of the url that i send out with curl (since msdn only accepts GET, not POST).
i haven't tried retrieving the user's contact address book, but this would just be a case of extending the scope element with whatever extra information you require (documented here http://msdn.microsoft.com/en-us/library/live/hh243646.aspx). as you can see from the http_params arrays, the scope parameter is used in each of the three oauth stages.
Try out a Hotmail/MSN/Live import on the CloudSponge test drive to see if that's the user experience you're hoping for.
If it works for you, you can use our widget or our API. If you want to use the API, we have a PHP wrapper already written for your convenience.
Please confirm your callback url is with http:// if you only put www.domain.com then get this issue..
I have a website..previously when I was uploading a new post in my blog..It was getting posted to twitter automatically. But since the new version of OAuth system..It no longer works...Can anybody help me to sort out what to change?
My code is :
'Twitter'=>array(
'enabled' => true, //set to false to shut off twitter integration
'username' => 'blogspott', //your twitter.com username
'password' => 'W3Sw9OpW6HvZYl', //your twitter.com pasword
'consumer_key' => 'TdQS15VHBdZNIrQ7RPqVQ',
'consumer_secret' => 'B2Xe5h3lHXVXUgoCAxgAIdJDTeBf6AywRoGiTwB7I',
'oauth_token' => '283508422-FkiIyZq2tpx1PQOyBLyWyomXY9OdMKxxSKGcg9d3',
'oauth_token_secret' => '548kxcZCvhytdRkJ405QeWONvMyXNEpSZszIMEYU4W4',
'tweet'=>'#%POST% for just %URL-TO-POST% %LINK%',
// Bit.ly / URL Shortening
// Within your Tweets, auto-append short URLs i.e., bit.ly/s8dJksm, to save on space.
// Sign up for an API account at http://bit.ly, and place the information
// for that account in the box below
'short_url'=>array(
'append_short_url'=>false,
'short_url_provider'=>'bit.ly', // current option: bit.ly only (default), more soon!
'bitly'=>array(
'login' => 'o_78ocugrkqtf',
'api_key' => 'R_734dbe3be47605c405f4e19ec35eb617'
),
)
),
I am using the right keys here..I've double checked it.
Twitter did not change its OAuth system recently. It is not concerned by the controversial Twitter API 1.1. So verify that you are doing it just like Twitter asks and that you do not use deprecated endpoints (Twitter removed some of them recently).
I'm on my own page, I'm admin and I'm already "like" this peage, but this code:
require_once "api/facebook.php";
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => SECRET,
'cookie' => true
));
$signedrequest = $facebook->getSignedRequest();
$uid = $facebook->getUser();
gives me just this data:
### USER ID ###
0
### SIGNED REQUEST ###
Array
(
[algorithm] => HMAC-SHA256
[issued_at] => 1330166798
[page] => Array
(
[id] => 304887859549216
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => us
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
)
So, getUser() = 0 and user id from signed request - empty.
What im doing wrong?
By default the "user" is the page, this way you can display content from your app relevant to the page. To determine who the user is, you can go through the standard backend redirects you would go through as if the user came to your app with no session/expired token. But you need to remember what page your were on since Facebook only passes that information on initial iframe load.
For a better user experience, I would use the Facebook javascript SDK. You can check everything in javascript and determine who the user is without performing any redirects. You can even prompt for authorization without reloading the page. If the user already had authorized your app, they see no changes and get no prompts, but you now have a "session" with that user and know their ID in javascript.
https://developers.facebook.com/docs/reference/javascript/FB.login/
For getUser you need to log in in your application , show te login/permission dialog
Just to add to this you can't currently get everything in the javascript SDK. It doesn't give you any of the user or page (for page tab) data which PHP SDK does.