i need to get twitter new followers using twitter API. I am able to get total followers but not able to get NEW followers.
$obj = new TwitterOAuth($keys['AppKey'], $keys['SecretKey'],$sKey2,$sKey3);
$detail = $obj->get('account/verify_credentials');
$return=$return+$detail->followers_count;
How to get new followers not total followers?
For authorized users you can use Twitter Stream API for track new followers:
https://dev.twitter.com/streaming/overview/messages-types#Events_event
I use it with C# library https://github.com/linvi/tweetinvi
and code is very simple:
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
var stream = Stream.CreateUserStream();
stream.FollowedByUser += (sender, args) =>
{
Console.WriteLine("You have been followed by " + args.User);
};
stream.StartStream();
I think there is same library for php too. Or you can try use Twitter Stream API from php directly
Related
I'm trying to get logs of video-calling that are in the URL of https://www.twilio.com/console/video/api/logs/rooms/csv. I'm trying the following code to do that, but in return, I'm getting 0 responses. How can we get the this data via Laravel?
$sid = "xxxxxxxxxx";
$token = "xxxxxxxxxx";
$twilio = new Client($sid, $token);
$calls = $twilio->calls
->read([], 20);
Log::info($twilio);
Log::info($twilio->calls);
Log::info($calls);
Is there any way to get this data in PHP with Laravel?
That is not the REST API resource, so not sure where you got that URL from?
https://www.twilio.com/console/video/api/logs/rooms/csv.
The REST resources are shown below.
REST API: Rooms
REST API: Participants
REST API: PublishedTrack
This show active tracks (not when the meeting is completed)
I know how to access Google Analytics data with Data Studio or with Google Apps script in Javascript:
var account = Analytics.Management.Accounts.list().items[0];
var webProperties = Analytics.Management.Webproperties.list(account.id);
...
var report = Analytics.Data.Ga.get(tableId, startDate, endDate, metric,
options);
But in PHP, how is it possible to retrieve the number of visitors of a specific website or specific page, from a Google Analytics account / property / view? i.e.:
input: analytics account login/password/website code 'UA-XXXXX-Y'
output: [19873, 17873, 13999, 21032, ..., 16321] (i.e. the number of visits on www.example.com for each of the 30 last days, as a list of integers or JSON)
You can use Google Analytics API client in PHP.
Google analytic api client library
You can use the Query Explorer to create the queries to check.
Code Example:
$analytics = new analytics('username', 'password');
$analytics->setProfileByName('user.name');
//set the date range for which you want stats for
$analytics->setMonth(date('n'), date('Y'));
// it could also be $analytics->setDateRange('YYYY-MM-DD', 'YYYY-MM-DD'))
print_r($analytics->getVisitors());
print_r($analytics->getPageviews());
The above example used the Google Analytics API client in PHP. It was the first library released in PHP. Six years later, this software is outdated. Google changed the API.
As an alternative you can use GAPI library.
Above is the example how it would work, you can include gapi class to make it functional.
GAPI Analytic Library
Another way is that you can use the Google Analytics Reporting API v4 for PHP.
You can obtain this using composer:
composer require google/apiclient:^2.0
Guide to usage of this library is at github
I use this package:
https://github.com/google/google-api-php-client
You can use it to access all the Google APIs from PHP, including of course Google Analytics
Here's an example of how to use it:
// create client object and set app name
$client = new Google_Client();
$client->setApplicationName('Your app name'); // name of your app
// set assertion credentials
$client->setAssertionCredentials(
new Google_AssertionCredentials(
'your_analytics_email#gmail.com', // email you added to GA
[
'https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents('/your/key/file.p12') // keyfile you downloaded
]
)
);
// other settings
$client->setClientId('your-client-id'); // from API console
$client->setAccessType('offline_access'); // this may be unnecessary?
// create service and get data
$service = new Google_AnalyticsService($client);
$from_date = date("Y-m-d",strtotime("-30 days")); // A month
$to_date = date("Y-m-d");
$response = $service->data_ga->get(
"ga:profile_id", // profile id
"$from_date", // start date
"$to_date", // end date
"ga:uniquePageviews",
[
'dimensions' => 'ga:pagePath', // Dimensions you want to include, pagePath in this example
'sort' => '-ga:uniquePageviews', // Sort order, order by unique page views from high to low in this case
'filters' => 'ga:pagePath=~\/articles\/[a-zA-Z0-9\-]+', // example url filter
'max-results' => '50' // Max results
]
);
foreach ($response["rows"] as $row) {
// ...do whatever you want with the results
}
Also, here's a guide on how to use the Google APIs:
https://developers.google.com/api-client-library/php/start/get_started
EDIT: You need to create credentials to access the Analytics API. You do it here: https://console.cloud.google.com/flows/enableapi?apiid=analyticsreporting.googleapis.com&credential=client_key. You need to register a project first, and then create the credentials. There are three options: API key, OAuth client ID and Service Account Key. I didn't want to use OAuth, so I used the Service Account Key. You can try using the API Key, in which case replace the $client->setAssertionCredentials(...) call for $client->setDeveloperKey(your_api_key). You can't use username and password directly AFAIK.
I am using the following to make my requests to Facebook
$facebook->api('/feed',
array(
'access_token' => $_SESSION['fb_access_token'],
));
However, I want to get the news feed of the user.
Not to be confused: I do not want the feed of a certain user, much less of a given page.
I want the News Feed/Feed Stream the user views when accessing Facebook, one that contains the posts of your friends, etc.
How is this possible?
Make an API call to /me/home or /user_id/home where user_id is the current session user.
You are also using the old PHP SDK
/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/me/home'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
Reference: https://developers.facebook.com/docs/graph-api/reference/v2.2/user/home
UPDATE:
The latest Graph API doc suggests the following:
As of October 6th, 2015, this endpoint is no longer available. Please consider using the /user-id/feed edge instead.
This effectively means we cannot access the user news feed provided by Facebook but will have to rely on /user-id/feed as an alternative.
The endpoint is me/home.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/home
The posts that a person sees in their Facebook News Feed.
Getting all recent notifications including read via Graph API, call:
graph.facebook.com/USER_ID/notifications?include_read=true
Just wondering how I would delete a video from YouTube using v3 of the API using the official Google PHP library.
I see this here:
Deleting a video from a playlist with YouTube Data API v3
$youtubeService = new Google_YouTubeService($client);
$playlistItems = $youtubeService->playlistItems;
$deleteVid = $playlistItems->delete($videocode);
Not sure if this is correct - does this work if the video is not in a playlist?
I also have the code for v2 of the API
Deleting YouTube videos using Zend/PHP
$videoEntryToDelete = $yt->getVideoEntry($videoId, null, true);
$yt->delete($videoEntryToDelete);
But rather use v3
For those looking for the answer it was this:
$youtube = new Google_Service_YouTube($client);
...
//do your authoraisation stuff + getting access token etc
...
$youtube->videos->delete('<Your Video ID>');
Hope that helps!
I have 3 events:
https://www.facebook.com/491594114271958 (Mad Haus)
https://www.facebook.com/569226999799343 (Deuglish)
539504962802119/ (Piffle)
All are being fetched via the PHP
$config = array();
$config['appId'] = $appId;
$config['secret'] = $secret;
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
$ev = $facebook->api('/'.$id."?fields=cover,description,location,name,owner,venue",'GET');
print_r($ev);
For some reason Mad Haus and Piffle do not return venue data but Deuglish does. All events return basic data such as title, description and start time. When I run them through the Graph API explorer the venue data is returned as expected but not through the PHP API, any ideas? I can not for the life of me see the difference with these 3 events.
Thanks,
Caroline
Well, if you don't want to wait for the Facebook developers to fix the bug, you can try the same by making a simple GET request (of course along with an Access Token) to Graph API using PHP cURL. Since you are able to retrieve the venues while using the Graph API explorer, I'm pretty sure you'll be able to get them by making a simple GET request using PHP cURL.
This however involves an overhead of parsing the received JSON object and dealing with errors will be a little difficult here. But you can give it a shot.