I want to get all the events of the logged in user, who has the app installed.
This is not intended to be a public app and is for me only. The user (me) has has given the app permissions like below:
I'm using this code:
<?php
// get all events for logged in fb user
require_once 'facebook.php';
$app_apikey = 'my-key-is-here';
$app_secret = 'my-secret-is-here';
$facebook = new Facebook($app_apikey, $app_secret);
$user_id = $facebook->require_login(); //returns my facebook user_id fine!
$events = $facebook->api_client->events_get($user_id); //returns nothing!
echo $events; //nothing
print_r($events); //no array to print
print_r(json_decode($events)); //no array to print
?>
Any ideas on why I'm getting a no results from events.get()?
It seems that you are using the old php-sdk? try using this one.
Make sure you have the user_events permission. Check this answer.
With the new SDK, it's as simple as:
$events= $facebook->api('/me/events');
Related
Sorry this may be a trivial question but I am new to PHP. In the documentation to retrieve project tasks, the following code is provided to connect to an Active Collab cloud account:
<?php
require_once '/path/to/vendor/autoload.php';
// Provide name of your company, name of the app that you are developing, your email address and password.
$authenticator = new \ActiveCollab\SDK\Authenticator\Cloud('ACME Inc', 'My Awesome Application', 'you#acmeinc.com', 'hard to guess, easy to remember');
// Show all Active Collab 5 and up account that this user has access to.
print_r($authenticator->getAccounts());
// Show user details (first name, last name and avatar URL).
print_r($authenticator->getUser());
// Issue a token for account #123456789.
$token = $authenticator->issueToken(123456789);
// Did we get it?
if ($token instanceof \ActiveCollab\SDK\TokenInterface) {
print $token->getUrl() . "\n";
print $token->getToken() . "\n";
} else {
print "Invalid response\n";
die();
}
This works fine. I can then create a client to make API calls:
$client = new \ActiveCollab\SDK\Client($token);
and get the list of tasks for a given project as shown in the documentation.
$client->get('projects/65/tasks'); // PHP object
My question is, what methods/attributes are available to get the list of tasks? I can print the object using print_r() (print will obviously not work), and what I really want is in the raw_response header. This is private however and I cannot access it. How do I actually get the list of tasks (ex: the raw_response either has a string or json object)?
Thanks in advance.
There are several methods to work with body:
$response = $client->get('projects/65/tasks');
// Will output raw JSON, as string.
$response->getBody();
// Will output parsed JSON, as associative array.
print_r($response->getJson());
For full list of available response methods, please check ResponseInterface.
If you wish to loop through tasks, use something like this:
$response = $client->get('projects/65/tasks');
$parsed_json = $response->getJson();
if (!empty($parsed_json['tasks'])) {
foreach ($parsed_json['tasks'] as $task) {
print $task['name'] . "\n"
}
}
I am trying to add an entry with this sample of code :
<?php
$service = new \Google_Service_Calendar($client);
$calendarListEntry = new \Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId($calendarId);
$calendarListEntry->setHidden(false);
$calendarListEntry->setSelected(true);
$calendarListEntry = $service->calendarList->insert($calendarListEntry);
The calendar is inserted but not shown on the Gmail Android App. I have to go to settings to display it.
I thought with setHidden() and setSelected() it would work but it didn't change anything. Plus, $calendarListEntry returned after insert has hidden = null.
Any thoughts ?
I'm trying to access my Google Analytics data using a service account. I've created one in the Developers Console and I've enabled the Google Analytics API in that same console, but somehow, I can't manage to pull data from the API.
I've used the script on this page.
My code is as follows:
<?php
$keyfile = 'google/key.p12';
// Initialise the Google Client object
$client = new Google_Client();
$client->setApplicationName('MyNAME');
$client->setAssertionCredentials(
new Google_AssertionCredentials(
'XXXX#developer.gserviceaccount.com', array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents($keyfile)
)
);
$client->setClientId('XXXX.apps.googleusercontent.com');
$client->setAccessType('offline_access');
$analytics = new Google_AnalyticsService($client);
$analytics_id = 'ga:UA-XXXXXX-1'; // http://productforums.google.com/forum/#!topic/analytics/dRuAr1K4waI
// get data for the last 2 weeks
$lastWeek = date('Y-m-d', strtotime('-2 week'));
$today = date('Y-m-d');
// Test connection
try {
$results = $analytics->data_ga->get($analytics_id, $lastWeek, $today, 'ga:visits');
echo '<b>Number of visits this week:</b> ';
echo $results['totalsForAllResults']['ga:visits'];
} catch (Exception $e) {
echo 'There was an error : - ' . $e->getMessage();
}
?>
Note: if it says "XXXX", that means I've removed part of the string for security purposes; the proper strings are in my actual script.
It should either display the number of users or a error, but I just get a blank screen. I'm sure the URL to the keyfile is correct.
Does anybody have suggestions on how to fix this? That would be much appreciated.
It looks like you are using your property Id (UA-XXXXX-1) in place of your view (profile) id. If you go to Google Analytics Query Explorer it makes it easy to see what your actual ga:XXXX view (profile) id is. Any given property can have multiple view's (profiles). This reference guide gives a good description of the parameters that this request requires.
I'm trying to use Codebird to show my latest tweet on a simple website. Unfortunately, I can't manage to make it work.
Here's what I did for now.
I created my App on Twitter Developer page. I obtained my Key/Secret and then my Token/Secret. Then I wrote my small PHP script and tried to show the timeline just to see if everything works. Here I encountered the problems. The code goes like this:
<?php
require_once ('codebird.php');
\Codebird\Codebird::setConsumerKey(MY_KEY, MY_SECRET);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken(MY_TOKEN, MY_TOKEN_SECRET);
$reply = (array) $cb->statuses_homeTimeline();
print_r($reply);
?>
(and obviously I put the various key strings in the correct arguments).
This code gives my an Array ( [httpstatus] => 0 ). So I tried
print_r($reply[0]);
But then nothing is printed out in the page.
Where am I wrong? How should I modify this code to get my last tweet? I'm a bit new with the new Twitter API, and a lot of stuff confuses me.
Thank you for your help!
I copied and pasted your code and it's not working.
I get error regarding the CodeBird class
Try:
require_once ('codebird.php');
Codebird::setConsumerKey('key', 'secret key');
$cb = Codebird::getInstance();
$cb->setToken('token', 'secret token');
$reply = (array) $cb->statuses_homeTimeline();
this should work just fine.
<?php
use Codebird\Codebird;
require 'vendor/autoload.php';
$cb = new Codebird;
$cb->setConsumerKey(
'Consumer_Key',
'Consumer_Secret'
);
$cb->setToken(
'Access_Token',
'Access_Token_Secret'
);
$reply = (array)$cb->statuses_homeTimeline();
echo '<pre>';
print_r($reply);
im trying to update my news feed on facebook. Im using the new graph api. I can connect to graph, but when i try to publish some content to the feed object, nothing happens.
here´s my code:
<?php
$token = "xxxx";
$fields = "message=test&access_token=$token";
$c = curl_init("http://graph.facebook.com/me/feed");
curl_setopt($c,"CURLOPT_POST", true);
curl_setopt($c,"CURLOPT_POSTFIELDS",$fields);
$r = curl_exec($c);
print_r($r);
this returns:
{"error":{"type":"QueryParseException","message":"An active access token must be used to query information about the current user."}}1
then I try to pass access_token via GET:
$c = curl_init("http://graph.facebook.com/me/feed?access_token=$token");
this returns:
{"data":[]}1
Am I doing something wrong?
thanks
I found my error!
I was putting CURL options as a string rather than constants.
oopps...