Facebook Page feed Script Has Stopped Working [duplicate] - php

This question already exists:
Instagram/Facebook deprecating many APIs [duplicate]
Closed 4 years ago.
After battling for many days to write a PHP script to access the feed data from selected public Facebook pages, I finally got the below code to work.
I deployed the script on my server and applied a cron to run it every hour or so for almost a month with no problems but yesterday suddenly it stopped working and now spits out the error:
Unsupported get request. Object with ID '483096775077541' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
What has changed, could someone please help?
<?php
$config['App_ID'] = 'xxxxxxxxx';
$config['App_Secret'] = 'ssssssssssssssssssss';
$token_url = "https://graph.facebook.com/oauth/access_token?"
."client_id=".$config['App_ID']
."&client_secret=".$config['App_Secret']
."&grant_type=client_credentials";
$grant = json_decode( file_get_contents($token_url) );
$page_i = 0;
$page_target = 1;
$graph_url = "https://graph.facebook.com/483096775077541/feed?access_token=".$grant->access_token;
while ($page_i < $page_target) :
$feedtext = file_get_contents($graph_url);
$feed = json_decode( str_replace('\n','<br />',$feedtext) );
foreach($feed->data as $data)
{
if( isset($data->message) ){
$lines = explode('<br />', $data->message);
echo '
<p>
<strong>'.$lines[0].'</strong>
<div>'.$data->message.'</div>';
echo '<div>'.$data->updated_time.'</div>
<div>'.$data->id.'</div>
</p>
';
}
}
$graph_url = $feed->paging->next;
$page_i++;
endwhile;

https://developers.facebook.com/blog/post/2018/04/04/facebook-api-platform-product-changes
As we begin enhancing our new app review process and make changes to our platform, the Events, Groups, Pages and Instagram APIs will no longer be available to new developers
Since this stopped working yesterday, it is definitely related to the recent changes. The only thing you can do is wait right now.

Related

google analytics api suddenly stopped returning data after working for many months

My analytics api stopped returning rows the other day. I see the data in the analytics api. What could cause this? Is it a quota issue? Is there some messages the api returns that could tell me what is going on?
It worked flawlessly prior to this. I'm not seeing any visible errors when I manually run the script. I am using composer to include the SDK, and it's up to date. I do appear to be able to initialize my Google_Service_AnalyticsReporting($client)
When I make the report request, I just don't get any rows or any indication as to why I am no longer getting any rows returned.
My code is based on the accepted answer here How to get the next 10,000 data from google analytics api using php?
I apparently am still getting data but the while loop never fires now. I have views where the next page token value is blank, and at least 1 where it is > 10000.
Any help on steps to take to trouble shoot this would be greatly appreciated. Issue started on 9.19
$data = $analytics->reports->batchGet( $body );
$cnt = 0;
while ($data->reports[0]->nextPageToken > 0 && $cnt < 10) {
// There are more rows for this report.
$body->reportRequests[0]->setPageToken($data->reports[0]->nextPageToken);
$pagedata = $analytics->reports->batchGet( $body );
$this->processResults($mysqli, $pagedata, $auth);
}
Checking if nextPageToken is a number fixed my issue.
if(is_numeric($data->reports[0]->nextPageToken)){
//nextPageToken is a number
$cnt = 0;
while ($data->reports[0]->nextPageToken > 0 && $cnt < 5) {
$body->reportRequests[0]->setPageToken($data->reports[0]->nextPageToken);
$data = $analytics->reports->batchGet( $body );
$this->processResults($mysqli, $data, $auth);
$cnt++;
}
}else{
//nextPageToken IS NOT A NUMBER
$data = $analytics->reports->batchGet( $body );
$this->processResults($mysqli, $data, $auth);
}

upgrading twitter api 1 to current version

I am not a hardcore coder but i have small knowledge i have attempted to fix this error we are getting regarding the Twitter api
there is a line of code that checks that a twitter name is currect which is sent via a form
$url = get_data("http://api.twitter.com/1/users/lookup.json?screen_name=".$name);
$xml = json_decode($url, true);
$id = $xml[0]['id'];
$av = $xml[0]['profile_image_url'];
if ($id != "")
What i understand
I understand that this version of twitter is no longer available and i need to update it to 1.1
What searching and research i have done
I have Searched the net for a quick answer for this but was not able to find any....
I have found this code https://github.com/abraham/twitteroauth/tree/master/twitteroauth
My question
How do i adapt the files to work within this file? i didnt post the whole code within the page as im not sure all of it is relevant.
Just use the 1.1 in the URL. That will do
http://api.twitter.com/1.1/users/lookup.json
-------^
Do like this...
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN,OAUTH_SECRET);
$account = $connection->get('account/verify_credentials');
$status = $connection->post('statuses/update', array('status' => 'Text of status here', 'in_reply_to_status_id' => 123456));
$status = $connection->delete('statuses/destroy/12345');
Documentation

Google Adwords Incorrect statistics

I'm using the Google AdWords PHP API to access statistics from our account. However, I'm getting some really strange read outs from the statistics through the api. I'm trying to access the stats for individuals Ads or Adgroups. The statistics returned, however, are way off what they are in the client center. The code I'm using:
$user->SetClientCustomerId($clientId);
$adService = $user->GetService("AdGroupAdService", ADWORDS_VERSION);
$selector = new Selector();
$selector->fields = array("Id", "Name", "Clicks", "Impressions", "Cost");
$selector->predicates[] = new Predicate("AdGroupId", "IN", array($adGroupId));
$selector->dateRange = $dateRange;
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
do {
// Make the get request.
$page = $adService->get($selector);
if (isset($page->entries)) {
foreach ($page->entries as $ad) {
$newLineObject->adName = $ad->name;
$newLineObject->clicks = $ad->ad->AdStats->clicks;
$newLineObject->impressions = $ad->adStats->impressions;
$newLineObject->cost = $ad->ad->AdStats->cost->microAmount/ AdWordsConstants::MICROS_PER_DOLLAR;
}
}
else {
print "No matching ads were found.\n";
}
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
When I print the results I get numbers that are considerably larger than those displayed in the client center. For example, for one partiuclar Ad the API reported 2.000.000 impressions, while the client center showed 56.000.
What am I doing wrong?
Your code seems correct to me. However, you problem may be that your date range in your code is different to the one you see in your client center. Make sure that you keep the same date range when you cross check.
Having tried using the method detailed above extensively, I have altered my code completely. I now use AdHoc Reporting (described here https://developers.google.com/adwords/api/docs/guides/reporting). This method was suggested to me by an AdWords developer. While this does not literally solve my question (i.e. why does the above code return incorrect statistics), it does provide an easy and clean way to obtain the data correctly.

Affiliate Window API integration in PHP

I am trying to write an application that integrates with the Affiliate Window API. The only problem I have is I have literally 0 experience in php and so find myself unable to debug even the most elementary of issues.
I downloaded the below code which is supposed to be a sample application. Unfortunately running it fails at the first hurdle:
Invalid argument supplied for foreach() in /Users/ravinthambapillai/Downloads/api.client/listmerchants.php on line 9
This is the error message I get when I run the below:
Can anyone help me with what I need to fix to get this right?
<?php
define('API', 'PS');
require_once('constants.inc.php');
require_once('classes/class.ClientFactory.php');
$oClient = ClientFactory::getClient(REDACTED, REDACTED, merchant);
$listmerchants = array('iCategoryId'=> 97, 'iMaxResult' => 10);
echo 'hello world';
$oResponse= $oClient->call('getMerchantList', $listmerchants);
foreach($oResponse->oMerchant as $details){
$name = $details->sName;
$strapline = $details->sStrapline;
$description = $details->sDescription;
$logo = $details->sLogoUrl;
$showurl = $details->sDisplayUrl;
$deeplink = $details->sClickThroughUrl;
$id = $details->iId;
if ($logo<>'') {
echo "<a href=".$deeplink." title='".$name."'><img src=".$logo.
" style='float:left; margin:5px;' alt='".$name.
" :: ".$strapline." :: ".$description." :: ".$showurl.
"' width=\"88\" height=\"31\" border=\"0\"></a>";
}
}
?>
Did you update the constants in constants.inc.php?
API_USERNAME needs to be set to your account ID, and API_PASSWORD needs to be set to your Affiliate API Password as seen at https://www.affiliatewindow.com/affiliates/accountdetails.php (when you're logged in)

PHP - Syncing MySQL Contacts with Exchange

As part of a PHP webapp I have MySQL contacts table. It is integrated throughout the app, allowing you add a contact, edit a contact or add a contact as a relation to another table. However, currently it is self-contained. The company would like it to sync with Exchange, so that contacts added to Exchange will show up on the webapp and contacts added on the webapp will show up through Exchange.
So I have two problems: 1) communicating with Exchange 2) syncing with Exchange.
As far as the basic communication goes, it looks like this library will be able to manage it https://github.com/jamesiarmes/php-ews. However, I am quite lost as to how to manage syncing and don't where to start.
The build-in way to sync items is via function called SyncFolderItems. Basically to Exchange everything, including contacts is a folder, so you'll just pass CONTACTS as DistinguishedFolderId in your sync request.
The sync works by donloading all the items for given account in batches of max 512 elements and after each batch it gives you SyncState as a refernce point for Exchange to know where you left off. So it gives you ability to do incremental sync.
Now, that's one way of course, meaning Exchange -> Your DB. The other way it aeound you should preform atomic updates/request - the moment you change/add/delete item form your db you should issue adequate request to Exchange server to keep data in sync, elese it'll be overwritten on your next SyncFolderItems.
You can read up more on SyncFolderItems # MSDN
If you'd like to see example of SyncFolderItems you can take a look # python version of EWSWrapper, it's been added in recently. Although it's python, you can still get the basic idea how to construct the request / handle response.
Hope this helps :)
I am aware that this topic is pretty old. However, for future reference find a solution below. It is using the above-mentioned library php-ews.
I have also just added this to the official php-ews wiki: https://github.com/jamesiarmes/php-ews/wiki/Calendar:-Synchronization
// Define EWS
$ews = new ExchangeWebServices($host, $username, $password, $version);
// fill with string from last sync
$sync_state = null;
$request = new EWSType_SyncFolderItemsType;
$request->SyncState = $sync_state;
$request->MaxChangesReturned = 512;
$request->ItemShape = new EWSType_ItemResponseShapeType;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->SyncFolderId = new EWSType_NonEmptyArrayOfBaseFolderIdsType;
$request->SyncFolderId->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType;
$request->SyncFolderId->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$response = $ews->SyncFolderItems($request);
$sync_state = $response->ResponseMessages->SyncFolderItemsResponseMessage->SyncState;
$changes = $response->ResponseMessages->SyncFolderItemsResponseMessage->Changes;
// created events
if(property_exists($changes, 'Create')) {
foreach($changes->Create as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// updated events
if(property_exists($changes, 'Update')) {
foreach($changes->Update as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// deleted events
if(property_exists($changes, 'Delete')) {
foreach($changes->Delete as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}

Categories