Google Contacts API name and email - php

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.

Related

SagePay: list of transactions

I'm just wondering if it's available to fetch list of all payments from SagePay. I'm currently able to get transaction details by providing transaction_id and send request to https://sagepay.com/api/v1/transactions/{$transaction_id}. I'm currently getting all payments by CSV export from SagePay dashboard, but I would like to automate it. Thank you in advance for help.
You can use the 'old' API to achieve this - just issue a getTransactionList command.
Documentation at: https://www.sagepay.co.uk/file/1186/download-document/reportingandapiprotocol102v0.5.pdf
You can do it easily, just give the required fields in the xml form and send request to respective url.
$crypt = MD5($string . '<password>' . $password . '</password>');
$xml = 'XML=<vspaccess>'.$string.'<signature>'.$crypt.'</signature>
</vspaccess>';
where $string is the whole xml before the password.
It will also help you making the signature field in xml syntax.
Read this pdf (page 85 for you) :-)

Create own bot on telegram with php

I saw a couple of days ago this tutorial on youtube.
It was very interesting, so I decided to make a own bot.
I used the code from the tutorial as a template:
<?php
$bottoken = "*****";
$website = "https://api.telegram.org/bot".$bottoken;
$update = file_get_contents('php://input');
$updatearray = json_decode($update, TRUE);
$length = count($updatearray["result"]);
$chatid = $updatearray["result"][$length-1]["message"]["chat"]["id"];
$text = $updatearray["result"][$length-1]["message"]["text"];
if($text == 'hy'){
file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=hello");
}
elseif($text == 'ciao'){
file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=bye");
}
The script worked if I execute the script manually. However when I use the webhook it doesn't work anymore. The tutorial said that $update = file_get_contents('php://input'); is the right way, to be used before $update = file_get_contents($website."/getupdates");. My question how can I use php://input to execute my script automatically? The script is on a server from "one.com" and the certificate is also from "one.com".
If you use selfsigned ssl you have to point to the ssl path ,,
use the ssh to run this command after filling it with your real data ,,
curl -F "url=https://example.com/myscript.php" -F "certificate=#/etc/apache2/ssl/apache.crt" https://api.telegram.org/bot<SECRETTOKEN>/setWebhook
After change to WebHook method, you need to put as follows, since now we are going to handle one message at time. For me works perfectly.
instead
$chatId = $updateArray["result"][0]["message"]["chat"]["id"];
to
$chatID = $update["message"]["chat"]["id"];
this is the answer for all of your problems.
follow this step after you got a secret token for your bot:
create file in your website https://yourdomain.com/secret-folder/index.php
create your php file like this :
<?php
$website = 'https://api.telegram.org/bot123456789:1234567890ABCDEF1234567890ABCDEF123/';
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (isset($update["message"])){
$chatID = $update["message"]["chat"]["id"];
$text = $update["message"]["text"];
if ( $text == '/start' ) {
// send welcome message
file_get_contents($website."sendMessage?chat_id=".$chatID."&text=Welcome to my bot");
}else{
// send another message or do your logic (up to you)
file_get_contents($website."sendMessage?chat_id=".$chatID."&text=some text here");
}
}
?>
Set Your Webhook from this bot #set_webhookbot
choose command or type ' ست وب هوک '
reply with your secret bot token ex: ' 123456789:1234567890ABCDEF1234567890ABCDEF123 '
reply with your webhook address 'https://yourdomain.com/secret-folder/index.php'
reply with /setwebhook
if you follow step by step its will work.
enjoy it !!
Sorry for digging up this old question so enthusiastically, I had exactly the same question as you.
I think actually the answer may be easier yet less satisfying as we hoped: I don't think it's possible to get a list of previous messages to the bot while using the webhook.
Namely: what this does, is run the PHP script directly as soon as the bot receives a message. Nothing is stored in an accessible database, hence no updateArray is returned.
I came across this example, which shows how php://input works. I guess the solution to display a list of messages would be, let the php script store the message in a database everytime a message is 'forwarded' via the webhook.
If anyone found something else: I'm very interested.
As per my understanding from your code snippet above, you need to use php://input within double quotes instead of single quotes. In php, we are having bing difference in this use case.

Fetch Contacts from google

I used google api to fetch contacts of google account. The code that I used is http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/contacts/simple.php
But when I run the code by applying my credential, it gives me the contacts but just their name. I want the contacts email address.
I always use this to fetch gmail contacts.
http://contactsimporter.com/address-book-importer-demo.html
Hope you will like this too.
It authenticates the user on our own end, doesn't send user to authenticate to gmail.
Just give it a try.
Here's the download link.
http://svetlozar.net/downloads/import.zip
refer this.
Google Authentication API Library with PHP for User Details
http://www.technew.in/forum_thread_621_Google-Authentication-API-Library-with-PHP-for-User-Details.html
You can find how to fetch emails on this link, the problem was on the example code.
This is part of the code refered in the link.
$req = new \apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full?max-results=9999");
$val = $client->getIo()->authenticatedRequest($req);
$xml = new \SimpleXMLElement($val->getResponseBody());
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
foreach($result as $title)
{
$emails[] = $title->attributes()->address;
}

pulling mentions from twitter with php

I am trying to retrieve mentions from twitter using php. The current code I have works fine to retrieve the user_timeline, however when I try to use the same code for the mentions I get an authentication error. What is the best way to retrieve mentions with userid, pictures, text, etc included?
if I change user_time to mentions I get an authentication error.
Here is the code I use now to retrieve user_timeline with php.
<?php
$xmldata = "http://twitter.com/statuses/user_time/usernid.xml";
$open = fopen($xmldata,'r');
$content = stream_get_contents($open);
fclose($open);
$xml = new SimpleXMLElement($content);
$screenname = $xml->status[0]->user->screen_name;
?>
You have to use OAUTH ("Returns the 20 most recent mentions (status containing #username) for the authenticating user."):
https://dev.twitter.com/docs/api/1/get/statuses/mentions
Try: https://github.com/abraham/twitteroauth or http://www.joeyrivera.com/2010/twitter-api-oauth-authentication-and-zend_oauth-tutorial/ and https://dev.twitter.com/apps/new

t.co messing up my url when posting through api

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

Categories