Getting user country Facebook API PHP SDK - php

Currently having a few issues accessing the country from a given user on facebook. I have requested the user_location permission and my graph API call also requests location however I am only ever returned the city and an ID for the location - never an actual country.
My requests etc are below. I am using the standard PHP SDK docs
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me?fields=birthday,name,statuses,photos,location' );
$response = $request->execute();
// get response
$response = $response->getGraphObject();
$data_we_need = array();
$data_we_need['name'] = $response->getProperty('name');
$data_we_need['birthday'] = $response->getProperty('birthday');
$data_we_need['location'] = $response->getProperty('location');
$statuses = $response->getProperty('statuses');
$data_we_need['statuses'] = $statuses->asArray();
$photos = $response->getProperty('photos');
$data_we_need['photos'] = $photos->asArray();
I am returned an results like:
[name] => xxxxxx
[birthday] => 05/14/1990
[location] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Facebook\GraphObject
[backingData:protected] => Array
(
[id] => 112087812151796
[name] => Gloucester, Gloucestershire
)
)
I need to be able to get country from the location data provided.
Any help would be massively appreciated.

As far as I know the location & hometown fields are user inputs (community pages), hence you won't get stable results using the facebook API. You might rather want to try detecting the country yourself with the IP.

Related

How to register webhook url on Twitter app using Abraham library in PHP

I'm trying to register a webhook url on twitter app and I'm using this package twitteroauth.
But facing following error after executing Twitter endpoint to register webhook.
stdClass Object(
[errors] => Array
(
[0] => stdClass Object
(
[code] => 214
[message] => Webhook URL does not meet the requirements. Invalid CRC token or json response format.
)
)
)
I was tried to register webhook through code as follows:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_POST['oauth_token'], $_POST['oauth_token_secret']); $webhookURL = "https://example.com/twitter/webhook"; $ucontent = $connection->post('account_activity/all/my_env_name/webhooks', array('url' => $webhookURL));
After reading some posts regarding this issue, I was tried the following code with url encoding:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_POST['oauth_token'], $_POST['oauth_token_secret']); $webhookURL = "https://example.com/twitter/webhook"; $ucontent = $connection->post('account_activity/all/my_env_name/webhooks', array('url' => urlencode($webhookURL)));
I also read in some articles and regenerate the keys, tokens of my app and newly generated key, tokens in code.
But not get success to register webhook url.
Execute the Twitter endpoint to get the webhook related details, but its giving empty array
{ "environments": [ { "environment_name": "my-environment-name", "webhooks": [] } ] }
Expected output after successful webhook url registration in this array response:
{ "environments": [ { "environment_name": "my-environment-name", "webhooks": [ { "id" => webhook-id-here, "url" => https://example.com/twitter/webhook, "valid" => 1, "created_timestamp" => some-date-time } ] } ] }
Please help me for this issue.

Email verification with Xverify

I am using API of Xverify for email verifiation
Below is my API code:
require 'XverifyClientAPI.php';
$api_key = 'myapikey'; // Your API Key
$options = array();
$options['type'] = 'json'; // API response type
$options['domain'] = 'addeddomainname';// Reruired your domain name
$client = new XverifyClientAPI($api_key,$options);
$data = array();
$data['email'] = 'test#xverify.com';
$client->verify('email',$data);
echo '<pre>';
echo "valid: ", var_dump($client->is_valid()), "\n";
echo "status: ", $client->status(), "\n";
print_r($client->getReponseAsObject());// Convert the json response into object
Here I have use API key which is provided in my xverify account and domain name which is added in my xverify account
but still its give me error like below
valid: bool(false)
status: bad_request
stdClass Object
(
[syntax] => 1
[handle] => test
[domain] => xverify.com
[catch_all] => unknown
[address] => test#xverify.com
[error] => 0
[status] => bad_request
[responsecode] => 504
[message] => Reach the API Limit
[duration] => 0.013515949249268
)
I am not getting what is the problem with this ,can any body help me ?
Make sure you are using the correct url to call the api, in my case i had to the the domian name us.xverify.com to make it work, before i was using only xverify.com which always gave me the result same as yours(api limit reached), to check the correct api call log in to your xverify account and then click on setting and select email and scroll to the bottom of the page and check the correct url. If the id was created in the us i guess you have to use us.xverify.com

Twitter API - how to check if user A follows user B

My problem is quite strange (at least to me) as I have a request URL that works in the console but throws the Sorry, that page does not exist error in my php script, even though the connection is up and running.
So this
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_secret']);
$user = $connection->get('account/verify_credentials');
print_r($user);
works great, the $user data is printed out on the screen.
However, I am unable to check a friendship status as:
$x = $connection->get('https://api.twitter.com/1.1/friendships/show.json?source_id=707482092&target_id=755811768&target_screen_name=assetspersonifi');
As I get the error.
When I put this request into the Twitter API console, it gives back the json that I don't receive in my php code.
I'm using Abraham's twitteroauth library but this does not work either:
$follows_faelazo = $connection->get('friendships/exists', array('user_a' => 'blfarago', 'user_b' => 'faelazo'));
if(!$follows_faelazo){
echo 'You are NOT following #faelazo!';
$connection->post('friendships/create', array('screen_name' => 'faelazo'));
} else {
print_r($follows_faelazo);
}
stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [message] => Sorry, that page does not exist [code] => 34 ) ) )
I read that friendships/exists API is no longer supported by the Twitter API and I should use friendships/show but how if it's not working as you see above?
To prove that everything else is working, I can follow others with
$connection->post('friendships/create', array('screen_name' => 'faelazo'));
Why?
I found a way. Here's the documentation
$following = $connection->get('friendships/show', array(
'source_screen_name' => $_SESSION['username'],
'target_screen_name' => $screen_name_to_follow,
));
An alternative would be
$following = $connection->get('friendships/lookup', array('screen_name' => $screen_name_to_follow));
Look it up in Twitter doc.

Not receiving webhook notification from drive, why?

Im trying to use push notification from Google Drive SDK for receive notification for all changes into an account, I follow the steps Registering domain, then creating notification channel and it works, I get this object Google_Service_Drive_Channel from google-api-php-client:
$client = new Google_Client();
$client->setApplicationName("APP_NAME");
$service = new Google_Service_Drive($client);
$key = file_get_contents('my_private_key_location.p12');
$cred = new Google_Auth_AssertionCredentials(
'email_address_from_the_client#developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/drive'),
$key
);
$client->setAssertionCredentials($cred);
// Channel
$channel = new Google_Service_Drive_Channel();
$channel->setId(uniqid());
$channel->setAddress('https://my.custom.url');
$channel->setKind('api#channel');
$channel->setType('web_hook');
$test = $service->changes->watch($channel);
print_r($test);
// Response printing the result
Google_Service_Drive_Channel Object
(
[address] =>
[expiration] => 1407171497000
[id] => xxxxxxxxxxxxxxxxxx
[kind] => api#channel
[params] =>
[payload] =>
[resourceId] => xxxxxxxxxxxxxxxxxxxx
[resourceUri] => https://www.googleapis.com/drive/v2/changes?includeDeleted=true&includeSubscribed=true&maxResults=100&alt=json
[token] =>
[type] =>
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
So, I go to the google drive account for move some file, but I still don't receive anything from the webhook inside the location specified "address" parameter.
I receive X-Goog-Resource-State = sync header just when the channel is created, but others events like (add, remove, trash, untrash, change, update) don't.
Any help, Thank's
I am guessing the Drive account you're editing isn't associated with that service account, as I don't see you using the sub parameter anywhere. Can you try it with web based OAuth 2.0 as a test so you can establish it is getting access to the same Drive account as the one you are modifying. Take a look at the Drive docs on Application accounts for more on this: https://developers.google.com/drive/web/service-accounts
This was the solution for my bug Delegate domain-wide authority to your service account

Twitter OAuth: users/search works but search/tweets does not

I want search for tweets in twitter. It is not working.
$parameters = array('q' => 'oauth');
$result = $connection->get('search', $parameters);
But when I do a user search it working perfectly.
$parameters = array('q' => 'oauth');
$result = $connection->get('users/search', $parameters);
I have also tried the below and that is also not working
$parameters = array('q' => 'oauth');
$result = $connection->get('search/tweets', $parameters);
What could be the reason?
Error message
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => Sorry, that page does not exist
[code] => 34
)
)
)
You seem to be using the library TwitterOAuth by Abraham Williams.
I know this is an old question but I have just had the same problem as OP and it might keep happening to anyone else since apparently this library has not been updated for a while.
The problem seems to be that Twitter is no longer accepting requests via the version 1 of their API. You have to change the $host variable in the file twitteroauth.php as follows:
/* Set up the API root URL. */
//public $host = "https://api.twitter.com/1/";
public $host = "https://api.twitter.com/1.1/";

Categories