t.co messing up my url when posting through api - php

im using php and the twitter api library- when i send my message through the following code my links get messed up- as far as I know I'm using the standard twitter php api?
$result = $this->tweet->call('post', 'statuses/update', array('status' => $title));
before i post
testing link tracking http://bit.ly/tvHaWN
after i post
testing link tracking http://t.co/ptdXXNDH<br>
anyone else had a similar problem?

As I can suggest your $title variable contains of mixed text and HTML. Twitter statuses need to be plain text. Stripping tags should help.
Try to strip all HTML tags inside $title variable.
For example:
$result = $this->tweet->call('post', 'statuses/update', array('status' => strip_tags($title)));

Related

Convert instagram page addresses to usernames

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);

Twillio: Script behind link runs without tapping link

I am sending sms using Twillio REST Api in Yii2. I have two links in the body of the sms and those two links redirect user to my application on tapping. The body is like this:
Would you recommend our company? Please click YES or NO below to begin the survey. For Yes, please click: $yeslink, for No, please click: $nolink
I am shortening those links using google short url API. So the sms gets sent.
This is how I am shortening the links:
$yeslink = Yii::$app->GoogleShortUrl->shortUrl($yeslink);
$nolink = Yii::$app->GoogleShortUrl->shortUrl($nolink);
This is how I am sending sms:
$sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'my_auth_token';
$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages: okay, well, here it is then
$client->messages->create(
// the number you'd like to send the message to: oh great, this is really easy to implement
$customers->phone, [
// A Twilio phone number you purchased at twilio.com/console: Yes I did purchase one, actually the client did :D
'from' => '+<twillio_number>',
// the body of the text message you'd like to send: hmmm
'body' => $sms_body
]
);
Now the problem is, the script behind first links runs even without tapping it. How do i stop it? Is this Twillio related issue or something else?
I got the problem. As I was using google URL shortening API to shorten the URL. It did the work for me but It hit the script behind the link. So removing shortening logic solved the problem for me. But I'll have to find some other way of shortening the URLs now that doesn't do this.

Google Contacts API name and email

This is my first post on this site, so forgive me if I butcher it, but I'll try to be a clear and straight forwards as possible.
I'm trying to use the Google Contacts API to import the name and email address from an authenticated users gmail account. I am getting the email address fine using the generic code supplied by Google itself. I've tried to modify it to grab the contact names as well to no avail. Any help would be greatly appreciated. Below is the code I am currently using.
$xml = new SimpleXMLElement($val->getResponseBody());
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
$name_result = $xml->xpath('//title');
foreach ($result as $title) {
echo "<div>".$title->attributes()->address."</div>";
}
foreach ($name_result as $name) {
echo "<div class='contact_alt'>".$name."</div>";
}
OK, so I managed to find the answer elsewhere on this site. Didn't mean to post a question with an answer that already existed here. I really did try to look around first so I didn't do that.
PHP GMAIL Contacts XML Parsing with DOMDocument and cURL
An alternative solution I use is asking the Google API to reply with JSON, rather than XML. Parsing the XML with the gd: namespaces gets tricky. The JSON comes back with contact names and emails and it becomes a matter of using json_decode().
$url = 'https://www.google.com/m8/feeds/contacts/%s/full'
$url .= '&access_token=%s'
$url .= &alt=json;
Just add the &alt=json to the request URL.

facebook api post to wall

I currently am able to post to a users wall however I would like the post to give a preview since what im posting is a link...
To explain myself better If i was to log into my facebook account and copy a link and paste it to my wall it displays an audio player (all the meta data is already configured, tested and working) however, using code to post this same link it doesnt show the audio player instead it only shows the link to click on. Is there a way i can make facebook display the audio player...?
Heres the code im using to post:
$fbResult = $facebook->api(
'/' . $userId . '/feed/',
'post',
array('access_token' => $access_token, 'message' => $url)
);
Thanks in advance for the help!
I’m assuming you’re posting the URL as part of your message parameter?
Do it by explicitly using the link parameter for the URL.
https://developers.facebook.com/docs/reference/api/user/#links

trying to fetch user tweet stream in php

I am using the following code, but it showing a 404 error
$url = "http://api.twitter.com/version/statuses/user_timeline.json";
$call = file_get_contents($url);
There's no 'version' version. The Twitter API is currently version 1, so you need http://api.twitter.com/1/statuses/user_timeline.json.
Do note that Twitter can't read your mind, so you'll need to tell Twitter which user's timeline you want to fetch... i.e. http://api.twitter.com/1/statuses/user_timeline.json?screen_name=ceejayoz

Categories