I have a link from the via which I can send sms. It works when I put it in the address bar and fill the required get params and press enter. But how can I load it in the middle of controller action (the framework is Yii2 if that matters) ? I tried with mail() but couldn't reach any result.
The link is like below:
http://sms.***********.com/httpApi/Send.aspx?phone=359.........&body=message&username=xxx&password=xxx
Can I make it with plain php or I have to it via javascript ? Thank you in advance!
cURL allows transfer of data across a wide variety of protocols, and is a very powerful system. It's widely used as a way to send data across websites, including things like API interaction and oAuth. cURL is unrestricted in what it can do, from the basic HTTP request, to the more complex FTP upload or interaction with an authentication enclosed HTTPS site. We'll be looking at the simple difference between sending a GET and POST request and dealing with the returned response, as well as highlighting some useful parameters.
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'YOUR API URL',
CURLOPT_USERAGENT => 'cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close().
You should use сURL.
$query = http_build_query([
'phone' => '359.........',
'body' => 'message',
'username' => 'xxx',
'password' => 'xxx'
]);
$c = curl_init();
curl_setopt($c , CURLOPT_URL , 'http://sms.***********.com/httpApi/Send.aspx/?' . $query);
curl_exec($c);
curl_close($c);
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 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'm making an OpenID / oAuth2 login process for a web app I'm building.
I am able to make an authorization request to Google+. There are several parameters returned in my redirect_uri:
access_token = averylongstring
token_type = Bearer
expires_in = 3600
id_token = anextremelylongstring
refresh_token = 1/Jo_tXhJtL3sQTBZURWyKWwebQSjxY1Rb-7sflDC74Pw
created = 1370140758
Then I perform a cURL GET that looks something like:
$url = 'https://www.googleapis.com/oauth2/v1/userinfo';
$curl_data = "?access_token=".$tokens['access_token']."&code=".urlencode('xxxxxxxxx.apps.googleusercontent.com')."&client_id=".urlencode('xxxxxxxxx.apps.googleusercontent.com')."&client_secret=".urlencode('xxxxxxxxx')."&redirect_uri=".urlencode('http://www.mydomain.com/oauth2callback.php')."&grant_type=authorization_code";
This gives me an id, which I presume is the successful conclusion to my authentication flow.
So, where did I lose my state variable between the
https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3A%2F%2Fwww.mydomain.com%2Foauth2callback.php&client_id=xxxxxxxxxxxxxx.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login&access_type=offline&approval_prompt=force&state={%22cid%22%3A%22%22%2C%22tid%22%3A%221370142477%22%2C%22app%22%3A%22anappname%22%2C%22Provider%22%3A%22%22}
...and my redirect_uri?
Looks like there are two redirects going to my callback url. In the first redirect, immediately following when the user allows access to their Google information, the url variables "state" and "code" are sent to my callback page. But then another call, the final authentication request, is made from my callback page, and the result of that is just a clean url without a query string.
So, during the first redirect to my callback page, I read the GET variables, and turn them into SESSION variables. Next, a cURL is performed (and I still don't have this part right, as I am making a cURL post to:
https://accounts.google.com/o/oauth2/token
...and my cURL code looks like:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('access_token' => $access_token,
'code' => $_REQUEST['code'],
'client_id' => 'myclientid.apps.googleusercontent.com',
'client_secret' => 'mylittlesecret',
'redirect_uri' => 'http://www.mydomain.com/oauth2callback.php',
'grant_type' => 'authorization_code',
'approval_prompt' => 'force')));
getting a:
{ "error" : "invalid_request" }
I really derive no joy in this part of my coding project.
I have a PHP/JavaScript site (offline). I am using http://crum.bs/ for shortening URLs.
Here, there are 2 types of APIs provided by crum.bs:
Simple Shorten, and
Advanced Shorten
I am currently using the simple shorten API. The base URL to make a GET request is http://crum.bs/api.php?function=simpleshorten&url=[insert url here].
Now, I am planning to change it to the advanced API which requires POST.
I can't find the Base for this anywhere on that page (Or in Google).
The API Reference Page is http://blog.crum.bs/?p=12. Does anybody know what it is?
From what I see you would submit your POST request to the same path
http://crum.bs/api.php
You just need to pass the variables in the request (which technically would look the same as the Simple version, just a different HTTP verb is used)
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "http://crum.bs/api.php",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array(
'url' => 'http://www.some-really-long-url.com/with/a/lot/of/text/etc.html',
'desc' => 'some other data',
),
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
The $result var will contain the JSON response from crum.bs service