Convert instagram page addresses to usernames - php

I have a web form, in this form my customers will put their Instagram page addresses, then I must export the username from the link
but I have a problem
people will put this addresses in some ways
for example:
https://instagram.com/username/
instagram.com/username/
https://instagram.com/username?igshare....
https://instagram.com/u/username
username
I am trying to found an api for this work
I send the link to the api, then it convert the link to username
Instagram hasn't this api, do you know which have this api?

You could do without an API using the parse_url() and substr() functions to respectively extract "/username" out of "instagram.com/username" and removing the slash at the start, like so:
//assuming you pass the URL to another page using a POST request
$url = $_POST['url'];
$username = substr(parse_url($url, PHP_URL_PATH), 1);

Related

Facebook Client OAuth settings domain not working with query strings

I'm trying to get the Auth working with Facebook but it keeps on telling me that my redirect URL is not working.
In the Valid OAuth Redirect URIs I have the following
https://localhost
The issue is that, I'm passing some additional query string to my callback, like
https://localhost?uuid=something&service=my_service
When attempting to Auth, I do get the request popup and then I get a redirect URL but then Facebook is telling me that the URL is not allowed.
If I test https://localhost?uuid=something&service=my_service in Facebook's Redirect URI Validator it's telling me it's not valid
How can I add a a URL including a dynamic query string ? I've tried
https://localhost*
But Facebook is telling me this is not a valid URL and won't let me save/add this URL.
#ceejayoz put me on the right track, I will answer my own question, that might help someone else.
Additional data must be passed in a state parameter such as
$data = json_encode($some_std_class);
$pdata = $fb_helper->getPersistentDataHandler();
$pdata->set('state', $data);
$login_url = $fb_helper->getLoginUrl($my_url, $my_permissions);

PUT / Soundcloud API with cURL

I'm using this code to get a user but how do it "like" a track via a PUT request in cURL & PHP?
// build our API URL
$url = "http://api.soundcloud.com/resolve.json?"
. "url=http://soundcloud.com/"
. "USERNAME-HERE"
. "&client_id=CLIENT-ID-HERE";
// Grab the contents of the URL
$user_json = file_get_contents($url);
// Decode the JSON to a PHP Object
$user = json_decode($user_json);
// Print out the User ID
echo $user->id;
See SoundCloud API Documentation - /users.
You can favourite a track for a user with a PUT request in the following format:
/users/{user_id}/favorites/{track_id}
If you don't know how to make the cURL request, Google it - there are hundreds of tutorials and answers on StackOverflow. Here is one example:
Querying API through Curl/PHP

Get my own full profile with LinkedIn API

For testing purposes, I'd like to get my own full profile datas from LinkedIn API.
So far my code looks like this :
// Fill the keys and secrets you retrieved after registering your app
$oauth = new OAuth("APIKEY", "SECRETKEY");
$oauth->setToken("Token OAuth", "Secret User OAuth");
$oauth->disableSSLChecks();
$params = array();
$headers = array();
$method = OAUTH_HTTP_METHOD_GET;
// Specify LinkedIn API endpoint to retrieve your own profile
$url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(name),educations:(id,school-name,field-of-study))?format=json";
// By default, the LinkedIn API responses are in XML format. If you prefer JSON, simply specify the format in your call
// $url = "https://api.linkedin.com/v1/people/~?format=json";
// Make call to LinkedIn to retrieve your own profile
$oauth->fetch($url, $params, $method, $headers);
$oProfile = json_decode($oauth->getLastResponse());
var_dump($oProfile);
Although I am getting basic profile informations (firstName,headline etc...) but when it comes to full profile informations I get an object with '...' as value everytime, although the informations exist.
I have r_fullprofile ticked in my LinkedIn app interface, so I don't know what I have to do to get these values.
I tried your query with my own account. It looks you issue is with the skills field.
You can see in the LinkedIn API documentation that skills are made up of a skill, and each skill has a name. If you only want the name returned the proper way to ask for it is
skills:(skill:(name)), whereas your request asks for skills:(name).
Here is an updated request for you:
GET https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(skill:(name)),educations:(id,school-name,field-of-study))?format=json

getting twitter username with access token

I've a php application and successfully create a function to save access tokens and secrets in the database. (It's about sending specific content to their profile)
I want to show them which twitter account they linked to my application. How can I get their twitter user with access token?
Thanks for help.
When you get the access token Twitter also returns a screen_name and user_id variables. You can use those instead of making an additional request to GET account/verify_credentials
Use this instead:
$credentials = $connection->get('account/verify_credentials')
and then to get username, name, and location-
$name = $credentials->name;
$username = $credentials->screen_name;
$location = $credentials->location;

Get user details from openid

I'm using lightopenid as the login system for a site and after successful login, I need the user's details like his first name, last name, email and date of birth..
How can I get this information from his openid? Suppose for google, I'm using the authentication url as: https://www.google.com/accounts/o8/id
Then after the validate() method returns 1, I'm redirecting the user to another page in my site. But how can I fetch the details of the user after login ?
FYI, I'm using openid for google, yahoo and aol.
And for facebook, I'm using graph api and for twitter, I'm using twitter oauth. Is there any way of fetching user data with these too? Please suggest.
Just read the manual:
http://code.google.com/p/lightopenid/wiki/GettingMoreInformation
$openid->required = array('namePerson/friendly', 'contact/email');
$openid->optional = array('namePerson/first');
before calling $openid->authUrl()!
Then
$openid->validate();
$userinfo = $openid->getAttributes();
$email = $userinfo['contact/email'];
$firstName = $userinfo['namePerson/first'];
You need to add a parameter to specify that you also want to receive data back from the OpenID request.
I append the following to my OpenID requests to get the email details.
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ax.mode=fetch_request&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.required=email
The first part specifies the namespace being used for the extended data.
The second part specifies that we are making a fetch request for the data.
The third part specifies the schema we are using for the email.
And the final part is specifying that we require the email to be returned.
I have tested this with Google and it works fine. I do not have the other accounts, so have not tested it for those.
OAuth and Facebook Graph API will have there own formats, so I am not sure on those ones.
$openid->identity = 'https://www.google.com/accounts/o8/';
// use the following line to obtain the required details. These are the only details that google mail provides.
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last');
header('Location: ' . $openid->authUrl());
Seemingly lightopenid provides a method for that:
$openid->validate();
$userinfo = $openid->getAttributes(); // associative array
It returns either SimpleReg or "Attribute Exchange" data. But only if the user agreed to that, I would hope.

Categories