Using twitterauth to try to post status updates. This is my code (which returns a 403 error from twitter when I try to post it):
$fact = "This is a status update. http://onth.is/iss" ;
$parameters = array('status' => $fact);
However, if I do this:
$parameters = array('status' => "This is a status update. http://onth.is/iss");
It post perfectly fine. I know it has something to do wit the URL, because if I remove it from the first code it works.
Any tips? Thanks in advance!
If you are referring to the twitteroath library then I don't see anything wrong with your code. However, you can speed things up a little bit by doing:
$parameters["status"] = "This is a status update. http://onth.is/iss";
The two statements are identical, except that the latter will create a syntax error :)
My guess would be that you need to urlencode() the string before sending it to Twitter, but not knowing the library you are using, I can't say for sure.
Related
I'm trying to use the Premium URL Shortener script from codecanyon, I have asked for support but they seem to be a little busy, so the response time is not to quick.
The issue I have is when the API sends the request to the url shortener script with the following shortened query for example purposes:
$short = "http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
Although the variables are being placed in the script correctly using echo function at the end of the script after the api request is sent shows they are correctly inserted like so:
http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan#smith.com
However if I click the shortened url provided to me from the script I only get the following url string appear in the browser:
http://myfullwebsite.com/email/quote.php?fullname=Dan
It seems as soon as there is a space or even if there is no second name such as Dan Smith and only Dan is the available name, it will not even apply the second ampersand or & sign.
I have tried to use urlecode() but still no joy and I've been pulling my hair out for the last 3 days!
As a novice beginner it has been somewhat difficult to try and achieve the end result and it seems unreachable so I would appreciate any kind help or advice if possible, Maybe I'm missing something so simple?
I've thought of having the url query build from an array of variables but as a novice I've tried one way and failed so not sure if I have done it wrong.
Here is my full api code where I have tried both with SESSION and GET but that is not the problem as the end result echos to the browser with the variables there.. it's only when you follow the shortened url link that you see they're missing.
<?php
session_start();
$fullname = htmlspecialchars($_GET["fullname"]);
$address = htmlspecialchars($_GET["address"]);
$postcode = htmlspecialchars($_GET["postcode"]);
$emailaddress = htmlspecialchars($_GET["emailaddress"]);
$short = "http://myurl/api?api=MYAPI&format=text&url=http://ukhomesurveys.co.uk/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
echo $short;
// Using Plain Text Response
$api_url = $short;
$res= #file_get_contents($api_url);
if($res){
echo $res;
}
?>
Hope I covered everything and hope I have not confused anyone. Thanks.
I think the good choice here is to encode your query with base64 and then pass it to the shortener. In your http://myfullwebsite.com/email/quote.php you just decode the query and use it. The standart PHP functions are base64_encode and base64_decode.
Did you try to encode URI using rawurlencode?
$url = rawurlencode('http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan#smith.com');
A little background, I'm passing a data-uri of an image, one of those
data:image/png;base64,iVBORw0KGgoAAAANSUhEUg
as a POST to a Nginx-HHVM server to be processed in PHP. Btw it works on PHP-FPM and not HHVM.
The POST passed in Javacript as an object is this:
{
data : data.uri,
transfer : community_header,
transfer_id 'f6d67f12-9de1-48c0-82e6-afdcfe97a031'
}
In PHP I get the data like so:
$data = file_get_contents("php://input");
if(is_string($data)){
$data = json_decode($data,true);
}
What is interesting is this is the result.
Array
(
[{"data":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAADICAYAAADGFbfiAAAgAElEQVR4Xuy9CbwlV1Uu/tVwhjvf2317TKfTmUMSEggyiIiKiCjDA1FBQMYAwgOZAhgIg8g8qaAs4QiAKwBk0JHWnU5xpyMoTLyBgbRYEHOT3KJMgeYiOziMhaVVmdNks1k5/0wglBeigCkNogj98vxzq10o0AEqZPz9HYiKyfRyaYudhN9nYLtQwtTkKOq2jY2tonKdhCbswWQmAs3Xw/8DWJkFg/A6MDIAAAAASUVORK5CYII] => ","transfer":"community_header","transfer_id":"f6d67f12-9de1-48c0-82e6-afdcfe97a031"}
)
Now I've truncated the data-uri for clarity by the array is really messed up and I cannot figure out. Does anyone have any insight?
This sounds like a bug, particularly if the result is different than with PHP-FPM. Can you file a bug on our GitHub issue tracker with the details, hopefully including an isolated repro case? It looks like you've already narrowed it down a lot, so hopefully getting an isolated repro isn't much work :)
I'll try to make it short.
When i set flash data like this
$this->session->set_flashdata('testing', $somevariable);
I should get something like this in session:
'flash:new:testing' => string 'Test'
And this works.
When I make a new server request it should say
'flash:old:testing' => string 'Test'
I don't get to this part. Even at first request (while it is still "new") i get boolean (false) when trying to get flashdata.
I should mention this is working in wamp, but not on my live site.
Any ideas?
Thanks in advance
It seems strange !
Maybe you should check the value of var_dump($somevariable) in your live site.
i need to do a "file_get_contents" on a URL and there has to be data posted to the url before the contents are retrieved. is this possible? maybe something like
$contents = file_get_contents($_POST"http://www.example.com/");
so that i can then work with the $contents variable?
You cannot*** POST data using file_get_contents, you must use something like cURL
* I mark this because it is actually possible taking advantage of the third parameter which uses http context(see example one). However it really isn't worth your trouble if you have something like cURL.
Ah, I have tried to do this. Simply put you can't unless you install new extra software on your sever and go through A LOT of hassel and server load.
Best bet is to use GET if at all possible!
:)
I have been trying to attempt to use the facebook share function in my website but i cant seems to have the right result.
Say:
i have a page called http://www.example.com/product.php?prod=lpd026n&cat=43
and i am using facebook's share function to have visitors to share the page in the FB wall.
i tried writing the link this way but i doesn't seems to be successful:
href="http://www.facebook.com/share.php?u=www.example.com/proddetail.php?<?php print urlencode(#$_SERVER['QUERY_STRING']!=''?'?'.$_SERVER['QUERY_STRING']:'')?>"
as the result the arguments in the URL came out to be in %26, %3D and etc..
Ie: example.com/proddetail.php?prod%3Dlpd026n%26cat%3D43
as some of you may know that the data after '?' is dynamic and i am planing to use the code above in the frame of the page, so it will have different query passed to the share link in every new item.
The end result that i want got to look like this:
http://www.facebook.com/sharer.php?u=http://www.example.com/proddetail.php?prod=lpd026n&cat=43
Not
http://www.facebook.com/share.php?u=http://www.example.com/proddetail.php?prod%3Dlpd026n%26cat%3D43
can anyone help me to solve this problem?
Thanks in advance!
Ps: if you are unclear, please ask me to further clarify.
This URL:
http://www.facebook.com/share.php?u=http://www.example.com/proddetail.php?prod%3Dlpd026n%26cat%3D43
is only partially-encoded. You actually need to fully URL-encode it before passing to FB, so that it won't interfere with FB's URL structure. I'm sure that their script will know how to parse it properly.
The correct method is:
$url = 'http://www.facebook.com/sharer.php?u='.urlencode('http://www.example.com/proddetail.php?prod=lpd026n&cat=43');
// evaluates to:
// http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.example.com%2Fproddetail.php%3Fprod%3Dlpd026n%26cat%3D43
Update: build your dynamic query
// Original URL
$url = 'http://www.example.com/proddetail.php';
if ($_SERVER['QUERY_STRING'])
$url .= '?'.$_SERVER['QUERY_STRING'];
// Final URL for FB
$fb_url = 'http://www.facebook.com/share.php?u='.urlencode($url);
This is what urlencode does, what is the problem with the link this way?
Edit: I do not use PHP, but I think the following will do the trick (omitted the urlencode):
href="http://www.facebook.com/share.php?u=www.example.com/proddetail.php?<?php print $_SERVER['QUERY_STRING']?>"
I guess K Prime is right.
u need to encode the whole url because the slashes and ":" are still causing problems in this link ;)
$url = 'http://www.facebook.com/sharer.php?u='.urlencode('http://www.example.com/proddetail.php?prod=lpd026n&cat=43');
should be fine for your purposes.