Facebook getting pages id issue using php - php

I have a facebook application and a tab page which links http://localhost/a/index.php, I have successfully add this tab page to my pages. I wrote in index.php
$checkLoggedIn = $facebook->getSignedRequest();
it return me like this
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1324648800
[issued_at] => 1324644411
[oauth_token] => AAACMkfuFjmIBAEJ9zqtJVvDK08aXlO1wSEFVNvekyCWcZBtnQcJ8BTCYfwZBMyrom5nazjPCsF56v4hLCBi2VywUzgrLSTYr9sbMmTWDN5QFFeOBfU
[page] => Array
(
[id] => 309081639123289
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => bd
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
[user_id] => 1549070809
)
its ok for me. I have also another link on that page is start.php with same code but it return to me like this
Array
(
[algorithm] => HMAC-SHA256
[code] => 2.AQAHgyMnInvOgkoU.3600.1324648800.5-1549070809|OMFOQPTFesejPmg0h2SfwwNGGEY
[issued_at] => 1324644436
[user_id] => 1549070809
)
what can I now? to get same object. because they are in same iframe.

This is because the facebook sdk only saves some information in the session (your second array). To remember the page, you have to manually save it.

Related

How to get pin image using pinterest api in php?

I have all the boards of logged in user and using pinterest api i am able to fetch the pins from given board but when it returns the json there is no image link, the image field return as null. So how to get image with oin content. Here is json retrieved.
Array ( [data] => Array ( [0] => Array ( [id] => 400327854358866609 [link] => https://www.pinterest.com/r/pin/400327854358866609/4837342446222323658/8737cad9ec4b46439289fbd4f22353f02255549d33a8999691d82b8642f42625 [url] => https://www.pinterest.com/pin/400327854358866609/ [creator] => [board] => [created_at] => [note] => Hello this is simple test [color] => [counts] => [media] => [attribution] => [image] => [metadata] => [original_link] => ) [1] => Array ( [id] => 400327854358814014 [link] => https://www.pinterest.com/r/pin/400327854358814014/4837342446222323658/3f1103b8d1c97de21f913293ee6062f4122313c931b054764167e96745f64465 [url] => https://www.pinterest.com/pin/400327854358814014/ [creator] => [board] => [created_at] => [note] => 55 Awesome Men’s Tattoos | InkDoneRight We’ve collected 55 Awesome Different Mens Tattoo Designs to inspire you! We also have the meaning and symbolism behind the common men’s tattoo designs... [color] => [counts] => [media] => [attribution] => [image] => [metadata] => [original_link] => ) ) [page] => )
In above json image or media key has no values.
If you use the "API explorer", and add the "image" field, one of the outputs is the URL of the original image.
https://api.pinterest.com/v1/boards/BOARD_OWNER/BOARD_NAME/pins/?access_token=MY_TOKEN&fields=id%2Clink%2Cnote%2Curl%2Cattribution%2Cboard%2Ccolor%2Ccreated_at%2Ccreator%2Cimage%2Cmedia%2Cmetadata%2Coriginal_link%2Ccounts
Or using the JS SDK eg:
PDK.request(thisRequest, {fields: 'id,note,link,url,image'}, thisCmd,
function( PDKdata){};
See my example here:
Example of using Pinterest API

cakephp ldap login with idbroker plugin

I am blocked with a strange problem. I have added a connection with auth to my application. This is a ldap connection, to do this is use the idbroker plugin from analogrithems. It works well in the developpement mode (Configure::write('debug', 2); in core.php), but when I put it to 0 the plugin is not able make request to the ldap. I have some error.
The error in the log is
2014-07-11 08:37:28 Ldap.error: Query Params Failed:Array
(
[conditions] => (&(objectclass=group) member=CN=toto,OU=Users,OU=Paris,OU=France,DC=world,DC=local))
[fields] => Array
(
[0] => *
[1] =>
[2] => +
[3] =>
)
[joins] => Array
(
)
[limit] =>
[offset] =>
[order] => Array
(
[0] =>
)
[page] => 1
[group] =>
[callbacks] => 1
[scope] => sub
[type] => search
[targetDn] => DC=world,DC=local
)
Error: Operations error
I try to debug it by myself, but I can't.

Server based Google Drive Service?

I am looking to build a Google Drive application to store image and document files from a website application, without the requirement of a visitor authenticating, or providing permission to access, etc. Seamless use of a googledrive service through a PHP interface.
Users will upload images/documents to a web form, and the files are stored on a GoogleDrive instead of local file system.
I'm just in need of assistance with this, as all the Google Client examples I've worked with require user based authorization, and permissions.
The code I have now seems to get me my Google_DriveService array:
require_once '../apis/google-api-php-client/src/Google_Client.php';
require_once '../apis/google-api-php-client/src/contrib/Google_PredictionService.php';
require '../apis/google-api-php-client/src/contrib/Google_DriveService.php';
session_start();
// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID = '########.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '##########developer.gserviceaccount.com';
// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = '##########-privatekey.p12';
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/prediction'),$key));
$client->setClientId(CLIENT_ID);
$service = new Google_PredictionService($client);
// Prediction logic:
$id = '9146497114232; # replaced with random numbers for this post
$hostedModelName= 'sample.languageid';
$predictionData = new Google_InputInput();
$predictionData->setCsvInstance(array('Foo Bar A Doo')); ## Not sure what this is or what I need here?
$input = new Google_Input();
$input->setInput($predictionData);
$result = $service->hostedmodels->predict($id,$hostedModelName, $input);
# print '<h2>Prediction Result:</h2><pre>' . print_r($result, true) . '</pre>';
// We're not done yet. Remember to update the cached access token.
// Remember to replace $_SESSION with a real database or memcached.
if ($client->getAccessToken()) {
$_SESSION['token'] = $client->getAccessToken();
}
$driveService = new Google_DriveService($client);
print_r($driveService);
exit;
I am returned a lengthy array of objects, and from there, I'm rather stone-walled.
Some of which looks like :
[service:Google_ServiceResource:private] => Google_DriveService Object
*RECURSION*
[serviceName:Google_ServiceResource:private] => drive
[resourceName:Google_ServiceResource:private] => revisions
[methods:Google_ServiceResource:private] => Array
(
[delete] => Array
(
[id] => drive.revisions.delete
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => DELETE
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
)
)
[get] => Array
(
[id] => drive.revisions.get
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => GET
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[response] => Array
(
[$ref] => Revision
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
[2] => https://www.googleapis.com/auth/drive.metadata.readonly
[3] => https://www.googleapis.com/auth/drive.readonly
)
)
[list] => Array
(
[id] => drive.revisions.list
[path] => files/{fileId}/revisions
[httpMethod] => GET
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[response] => Array
(
[$ref] => RevisionList
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
[2] => https://www.googleapis.com/auth/drive.metadata.readonly
[3] => https://www.googleapis.com/auth/drive.readonly
)
)
[patch] => Array
(
[id] => drive.revisions.patch
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => PATCH
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[request] => Array
(
[$ref] => Revision
)
[response] => Array
(
[$ref] => Revision
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
)
)
[update] => Array
(
[id] => drive.revisions.update
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => PUT
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[request] => Array
(
[$ref] => Revision
)
[response] => Array
(
[$ref] => Revision
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
)
)
)
)
[version] => v2
[servicePath] => drive/v2/
[resource] =>
[serviceName] => drive
I think you should look into using a service acccount for this.
https://developers.google.com/drive/web/service-accounts
By using a service account you wont have to worry about people loging in. Everthing will always be uploaded to the same service account.

How Do I access Data in Facebook Array with PHP?

I have made a simple facebook register widget.
On register the App sends the data to send.php
On send.php I have
print_r($response);
And I get something like this:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1367953200
[issued_at] => 1367946138
[oauth_token] => BAAE0refKufgBAORkK7hUaVpF8MnFygoqHAHrO3nRJMyNjvJx6RjiMjoqbz2YlfqeogcIPGJJaIgD0xtxhBj1WRgQ5F5SidjwM7ZCKOyZBlEuatIqIccbjGj2uMV5hqtKtZA1g7hOEqMeZAEwmnO6SgRgsb9ittKZCDnPfoxYxCxZAZBAhIKX457IG5ZB4yknv9FZB8QUG7Pt0mfBRQUYG12KoTmO7QRH20LP65FyPqTi7mAZDZD
[registration] => Array
(
[name] => derp derp
[email] => ddddd#gmail.com
[location] => Array
(
[name] => Vienna, Austria
[id] => 1.1116511224109E+14
)
[gender] => male
[phone] => sss
)
[registration_metadata] => Array
(
[fields] => [ {'name':'name'}, {'name':'email'}, {'name':'location'}, {'name':'gender'}, {'name':'phone', 'description':'Phone Number', 'type':'text'},]
)
[user] => Array
(
[country] => at
[locale] => en_US
)
[user_id] => 100000506481284
)
So the data gets passed without a problem but how can I access a specific value?
For example text book array stuff doesnt appear to be working like:
print $response[0];
Gives me an error:
Notice: Undefined offset: 0 in C:\xampp\htdocs\ddd\send.php on line 38
How else can I access the data?
For example how could I store country, email, name or whatever in their own variables so I can echo them later? Its there but I cant seem to figure out how to "digest" it properly with php.
There is no index 0 in the array you pasted..
Use it like
$email = $response['registration']['email'];
If it was an object instead of an array you would do
$email = $response->registration->email
This is very basic PHP array handling.
http://php.net/manual/en/language.types.array.php

getting story tags from graph api returns strange id results for the tagged

The best way for me to explain this is to show you. Seems like a float() error in a 64bit system.
when i call /anotherfeed/feed or any page for that matter, posts with story_tags return some of the id's as a float error.
sample story tag with float error in id. [id] => 1.7153566624E+14
My question is, how do i fix this, or what am i doing wrong? all i am doing is looping in a foreach statement.
if($fvalue[story_tags]){
echo 'Tags: ';
$sTags=$fvalue[story_tags];
foreach ($sTags as $skey=>$svalue){
foreach ($svalue as $gkey=>$hvalue){
$id=$hvalue[id];
echo ''.$hvalue[name].' '.$id.' ';
}
}
}
[story_tags] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 1.7153566624E+14
[name] => Another Feed
[offset] => 0
[length] => 12
[type] => page
)
)
Array
(
[data] => Array
(
[0] => Array
(
[id] => 171535666239724_156133294510726
[from] => Array
(
[name] => Another Feed
[category] => App page
[id] => 171535666239724
)
[story] => Another Feed shared Non-Profits on Facebook's photo.
[story_tags] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 1.7153566624E+14
[name] => Another Feed
[offset] => 0
[length] => 12
[type] => page
)
)
[20] => Array
(
[0] => Array
(
[id] => 41130665917
[name] => Non-Profits on Facebook
[offset] => 20
[length] => 23
[type] => page
)
)
)
[picture] => http://photos-d.ak.fbcdn.net/hphotos-ak-ash3/557037_10150932300320918_1908237167_s.jpg
[link] => http://www.facebook.com/photo.php?fbid=10150932300320918&set=a.85612830917.95996.41130665917&type=1
[name] => Wall Photos
[caption] => Have you heard of the #[159208207468539:274:One Day without Shoes] (ODWS) campaign? ODWS is an annual initiative by #[8416861761:274:TOMS] to bring awareness around the impact a pair of shoes can have on a child's life.
During the 2012 campaign, #[20531316728:274:Facebook] drove 20% of traffic to the ODWS microsite and TOMS even launched a Facebook-exclusive "Barefoot & Blue" giveaway with #[25266987484:274:Essie Nail Polish] for the second year in a row.
We think this is a pretty cool example of creating exclusive content around an important initiative that keeps people engaged and involved!
[properties] => Array
(
[0] => Array
(
[name] => By
[text] => Non-Profits on Facebook
[href] => http://www.facebook.com/nonprofits
)
)
[icon] => http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif
[type] => photo
[object_id] => 10150932300320918
[application] => Array
(
[name] => Photos
[id] => 2305272732
)
[created_time] => 2012-07-02T17:57:23+0000
[updated_time] => 2012-07-02T17:57:23+0000
[comments] => Array
(
[count] => 0
)
)
solution:
cURL - had to use number format with PHP_EOL to solve in cURL.
// $locs = curl call to graph api for /anotherfeed/feed, still need solution for foreach.
$locs=json_decode($returned, true);
$stId=number_format($locs[data][1][story_tags][0][0][id], 0, '', '').PHP_EOL;
echo $stId;
PHP-SDK
solution is same, long numbers in the foreach loop need to be ran through number_format.

Categories