Is it possible to get INSTAGRAM user details through API from localhost ?
Because I am trying to doing this from localhost but unable to fetch the information.
After click the login url it redirect me to the INSTAGRAM and after successfully login and authorize the apps it redirect me properly in my callback URL with code. But when I am trying to fetch the info (cURL) using access token then it return null.
But same code run perfectly in live.
Make sure the Curl option CURLOPT_SSL_VERIFYPEER is set to false. Find the Curl request in your code and add or edit an option that will look something like this:
$ch = curl_init();
...
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); <<-- Add this line
Ultimately I resolved the problem. now I am able to connect to Instagram.
I use the CodeIgniter Instagram Library by Ian Luckraft.
In config file I just change the
$config['instagram_ssl_verify'] = FALSE;
By default it was TRUE.
Yes it is possible.
You can try using Instagram api wrapper which is made by Galen Grover
https://github.com/galen/PHP-Instagram-API
Mine's works just fine
in instagram .config.php in your localhost
you must set 'apiCallback' =>
to 'http://localhost/instagram/instagram/'
folder of your success.php
<?php
// Setup class
$instagram = new Instagram(array(
'apiKey' => '',
'apiSecret' => '',
'a
?>piCallback' => 'http://localhost/instagram/instagram/' // must point to success.php
));
Related
I am trying to show Instagram content from a user (mines) on a website. My client-side page would make an AJAX request to my server-side script, which in turn, would do the necessary stuff to pull the content from Instagram API (using cUrl) and send back a JSON response.
Sadly, I am little bit confused with the Authentication instructions, particularly Step One: Direct your user to our authorization URL.
In order to get an access_token to work with the API, I need to pass client_id, redirect_uri, and code. I have the client_id and redirect_uri. The problem is the last item, code, which gets found after redirecting from https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code. The redirected page will be REDIRECT-URI?code=CODE which has the CODE to use to make the request to get the access_token.
Is there a way to "automate" this last part ? Or more precisely, is it possible to make a request (using cUrl) and then grabbing this CODE
Hopefully, this is clear. Unlike other APIs, Instagram seems to make things difficult. My goal is so that when users come on the page, they will see a gallery of images from my Instagram account. They shouldn't need to log into Instagram or do anything to see these images.
Edit
$clientId = 'XXX';
$clientSecret = 'YYY';
$redirectUri = 'ZZZ';
// step 1: authorize
$url = "https://instagram.com/oauth/authorize/?client_id={$clientId}&redirect_uri={$redirectUri}&response_type=code";
try {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => $url
));
$data = json_decode(curl_exec($ch), true);
// how to get CODE from response?
curl_close($ch);
} catch(Exception $e) {
echo $e->getMessage();
}
I'd like to use the method vimeo.videos.getInfo to get the info on a private video uploaded to my account. I'll only ever use this application on one website, so I'm hard coding the access token into the code.
I'm using the official PHP library for the Vimeo API (https://github.com/vimeo/vimeo.php).
So here's what I have so far...
$vimeo = new Vimeo($apiKey, $apiSecret, $accessToken);
All good. At first, when I tried the sample code from the example:
$user_data = $vimeo->request('/me');
print_r($user_data);
That returned an empty array:
Array (
[body] =>
[status] => 0
[headers] => Array
(
)
)
I noticed they mentioned if the array is returning empty, it probably had something to do with an invalid SSL certificate. Right now, I'm just developing on localhost, so I set CURLOPT_SSL_VERIFYPEER to false (thanks to these instructions: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/). I added it to the array on line 112 in vimeo.php:
$curl_opt_defaults = array(
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false);
As soon as I did that, I was able to return the information about the authenticated user.
But this still is returning an empty array:
$params = array(
'video_id' => 95307197
);
$videos = $vimeo->request('vimeo.videos.getInfo', $params);
print_r($videos);
Same with any methods I try to put in there. Did I do the CURLOPT_SSL_VERIFYPEER thing wrong or is something else wrong with my syntax?
I thought that I might share my solution which took me some time to figure out. I also wanted to access private video data, namely the number pf time the video played. Here are my steps:
Create an app on Vimeo and get the Client Identifier, Client Secret, and generate an Access Token with the properties Public, Private, and Interact. You may need to add or remove properties based on your access need.
Download from Vimeo the PHP source code.
Strangely, at least in my case, the code had a wrong syntax on line 473 in the statement $name = array_slice(explode("/", $file_path), -1)[0]; to solve it remove the [0] at the end! In fact I didn't need to call this function to know if it did any harm, but this solved my problem. Am on Dreamweaver by the way.
More strangely, the PHP code provided my Vimeo can not do authentication with their new system so you need to add this code curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); before every $response = curl_exec($curl); statement. This should be 3 additions.
Finally, create your own PHP script to access the private video.
Here is my Code:
require("../Vimeo PHP path/autoload.php");
use Vimeo\Vimeo;
$client_id = "*****"; //your Vimeo number here
$client_secret = "*****"; //your Vimeo number here
$access_token = "*****"; //your Vimeo number here
$vim = new Vimeo($client_id, $client_secret, $access_token);
$response = $vim->request("/videos/****"); //your Vimeo PRIVATE video ID here
echo $response["body"]["stats"]["plays"];
In my case I did echo for the number of plays only, but you can print the whole body. Hope this helps someone too.
Thanks to this example I solved the same issue, in the current api at _request method(line 125) add the curl option CURLOPT_SSL_VERIFYPEER and set it to false so you will have an array like this:
$curl_opt_defaults=array(CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER=>false);
and that's all :) hope this helps someone else.
Hopefully this helps someone else. The Vimeo API documentation is all out of whack and the new API docs link back to the older API docs, which only adds to the confusion.
The new API doesn't use the methods from the Advanced API, it uses the endpoints here https://developer.vimeo.com/api/endpoints
Here is the code that eventually worked for me:
$videos = $vimeo->request("/videos/$video_id");
print_r($videos);
I am currently attempting to create a page with cURL instructions that does the following:
Take the following link, send a GET request to it, and retrieve the results.
http://login.yahoo.com/config/login?login=xxxxxxx&passwd=yyyyyyyy&.done=http://m.yahoo.com/mail
xxxxx - username
yyyyy - password
Easy, right? Not really. Since the page that is to be returned, is designed to automatically log you in your Yahoo Mail inbox.
I tried with:
<?php
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://login.yahoo.com/config/login?login=xxxxxx&passwd=yyyyyyy&.done=http://m.yahoo.com/mail',
CURLOPT_USERAGENT => 'something-here'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
echo $resp;
?>
I do get a response, but all it's about is the Yahoo Mail login page. It doesn't actually execute the login and retrieve the related Yahoo inbox.
How would I go about doing that with cURL?
After some extensive testing.. I decided to see as why this was not working and I was interested in #Sammitch's comment that it won't work..
I first tried using my own HTTP Requests class to login and I failed. the response always stayed empty but if I visited the URL from my browser it would work. I turned on the developer tools in Chrome and went to the network section and tried logging in
It seemed that that page posted the data into another page which is
http://login.yahoo.com/config/login_verify2?login=xxxxxx&passwd=yyyyyy&.done=http://m.yahoo.com/mail
After altering my cURL code to work with that URL directly it signed me in.. so this is the solution to your question.. basically the URL you were using did not work and the one that should work is shown above.
<?php
require "facebook.php";
$facebook = new Facebook(array(
'appId' => '3288##########',
'secret' => 'ca2##################',
));
$user = $facebook->getUser();
I have made the app in the graph api and I have very little knowledge of graph api . I want to make a facebook login page in which user clicked on it and my app will generate the oauth for the user . after that i need the USERNAME, EMAIL,BIRTHDAY,NAME in the fre filled forms
I'm searching for this code from 3 night, but i didn't find the solution! If you have a suggestion, please write to me it! Please, anyway thanks and good day :)
You could use POST request to simulate login. I don't know Facebook's inputs, so you need to look closely into it's HTML, but here is a code for a simple PHP cURL request.
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.facebook.com/login.php',
CURLOPT_USERAGENT => 'Facebook Login',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'username' => 'username',
'password' => 'myfbpass'
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
Of course, Facebook has automatic login detection by using those hidden fields for getting the sessions, but using DOM Document, you can easily get those values and emulate it, at least thats how I was able to simulate login for http://z8games.com/
Good luck
Code Credit:
http://codular.com/curl-with-php
Edit:
If you are lazy, you can go ahead and try this page - http://www.daniweb.com/web-development/php/code/290893/facebook-login-with-curl
Temboo makes it simple to implement Facebook OAuth by breaking the process down into two steps:
ÌnitializeOAuth returns the Facebook authorization URL that you need to show your users so that they can grant your app access to their Facebook accounts.
FinalizeOAuth returns the access token you need to programmatically read/write a user's Facebook data.
What's more, you can test these calls from your browser and generate the source code you need in the language of your choice.
Here's a short video that shows you how to do this with Temboo, and you can check out an example and source code here.
(Full disclosure: I work at Temboo, so let me know if you have any questions!)
I was trying to get the feeds of friends' fan pages with a cURL and to post a like via app.
The cURL GET works fine, but when it comes to liking the object (that has for sure likes enabled because it's facebook), all I get is a boolean (and no action).
I had seen on SO that you post a like with
($access_token, "https://graph.facebook.com/$post_id/likes", 'POST')
However, it is not working (it says either that the app has no permissions to do that, or that I need a valid url).
I have tried all possible solutions but nothing seems to work. The profile is mine, the access token too, and I gave publish_stream permissions to my own app.
After having given a try to the SDK PHP Likbrary, I tried a direct cURL post, with the following code:
function likeit($url){
//open connection
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, $url);
curl_exec($ch);
curl_close($ch);
}
The execution i a puzzle. When it does not return an OAuth Exception it returns boolean and stops there (there is no way for me to "like" the post I want to like). The last attempt (but I've tried them all, even the whole url in some tests) is
foreach ($feeds->data as $feed_data)
$message = $feed_data->message;
$title = $feed_data->name;
$link = $feed_data->link;
$id = $feed_data->id;
$myaccesstoken = "longlastingaccesstokenstring";
$post=likeit($myaccesstoken, "https://graph.facebook.com/$post_id/likes", 'POST');
Does anybody have a suggestion on how to do this? It seems trivial and yet there is no way for me to accomplish it. Thank you so much in advance!
I've found a solution, and thus am posting it here for future reference (hoping it is helpful for anybody with the same problem):
the only problem was that after the new permissions with facebook I needed to re-authorize my app.
After that, it is possible to post a like with the SDK facebook library, normally:
$facebook->api("/$id/likes", 'post', array(
'access_token' => $myaccesstoken));
No need to use cURL directly. Hope this helps someone with the same question.