Update Twitter Status using CURL - twitter

I have a problem while updating twitter status by username and password.
Here is the Code for that:
$username = 'username';
$password = 'password';
$message = 'Testing';
$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //basic authentication
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
echo $buffer;
This is not for only one user so that I can not use OAuth(means using consumer key and other token). I have already tried this: http://www.1stwebdesigner.com/tutorials/how-to-update-twitter-using-php-and-twitter-api/ but i can not pass multiple user's username and password for updating multiple twitter status.
Please help me on this.

You won't be able to update twitter status by username and password via curl any more - basic authentication was deprecated/turned off by Twitter several months ago (August 2010). Updates and such by third party applications now have to be done via oauth authentication.
By the way - considering you're using PHP - I'd suggest using either the PEAR Services_Twitter package or the Zend equivalent.

You can not use user name and password to update a Twitter status no matter how many users you have. This no longer works. It has been turned off. You must use OAuth. OAuth allows multiple users to log into Twitter on your site. When they do that, you get a copy of their OAuth tokens. You then use these tokens to send tweets to their accounts. You will still find documentation for using basic authentication to do this online, but all of these are out of date. Basic authentication is no longer available on Twitter.

First you have to use cookie each time you update user status, then destroy cookie after each success status update.
Second, put this condition in loop to update all user's you wont.
See this may help you:
http://blancer.com/tutorials/73877/how-to-authenticate-users-with-twitter-oauth/

Related

Does an AccessToken also work on Open Data Calls like /search?

So, im working on an Application which compares your youtube channel Data with other similare youtube channels.
Currently im working on the authentication of an user with his youtube account, therefore im Using the OAuth Client.
I already got an code which i can exchange for an access_token, which also works.
Sadly, the access_token which i get does not work for an simple /search call and gives me an HTTP 400 -> keyinvalid
The same call works with an generated ApiKey just fine, but i would prefer to use OAutch.
My question is, does an accessToken not work with public calls like /search? If it does, what could be my problem here?
Thanks in Advance!
EDIT: Added Code Examples
Step 1: I call the OAuth client with the following url call in an new window with window.open(url)
https://accounts.google.com/o/oauth2/v2/auth?
scope=https://www.googleapis.com/auth/youtube.readonly&
access_type=offline&
include_granted_scopes=true&
state=state_parameter_passthrough_value&
redirect_uri=https://website.com/&
response_type=code&
client_id=9791...7bng.apps.googleusercontent.com"
In the Response I extract the Code which looks something like this
4/1QCLZnwsntp...sNcE
Send this code over an REST API to my Backend which uses this code to exchange it for an access_token with an PHP curl POST call
$this->connection = curl_init();
$url = 'https://www.googleapis.com/oauth2/v4/token';
$param = 'code='.$this->credentialsTemp['code'].'&client_id='.$GLOBALS['Youtube-Credentials']['clientId'].'&client_secret='.$GLOBALS['Youtube-Credentials']['clientSecret'].'&redirect_uri=https://website.com/&grant_type=authorization_code';
curl_setopt($this->connection, CURLOPT_URL, $url);
curl_setopt($this->connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->connection, CURLOPT_TIMEOUT, 20);
curl_setopt($this->connection, CURLOPT_POST,true);
curl_setopt($this->connection, CURLOPT_POSTFIELDS, $param);
$resp = curl_exec($this->connection);
curl_close($this->connection);
$acces_token = json_decode($resp,true)["access_token"];
in $acces_token should be my access_token which at the Moment looks close to this ya29.GlyTBtFMdLqKbvgaps...SA2pBORo_Am5UuBuxo8g

Checking if a facebook profile is verified or not?

I am developing an app in which I want to know if a facebook authorized user has a verified profile or not. I can see that there is a is_verified field that facebook provides. I am just not getting it in the response I get from OAuth. Is there any permissions issue? I am using permissions public_profile,email. Please guide me on this.
You can ask 'is_verified' field in your query. You can try below code as a sample and u can take the appropriate part of the code to integrate in yours. public_profile,email permission is enough to get this field. result will be a bolean
$fb_page = 'barackobama'; //any fb page,fb profile
$access_token = ''; //your access token
$url = "https://graph.facebook.com/v2.2/".$fb_page.'
?access_token='.$access_token.'&fields=is_verified';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
$details = json_decode($result,true);
echo "verified:".$details['is_verified'];

EventBrite API - How Do I Get Only Live Events for my User?

I'm using PHP and CURL to try and get all my account's events from EventBrite's web service.
I'm running this script (edited down slightly):
$curl = curl_init();
$hdr = array();
$hdr[] = 'Authorization: Bearer <MY TOKEN>';
$hdr[] = 'Content-type: application/json';
curl_setopt($curl, CURLOPT_HTTPHEADER, $hdr);
curl_setopt(
$curl,
CURLOPT_URL,
'https://www.eventbriteapi.com/v3/users/me/owned_events/?status=live'
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$events = curl_exec($curl);
print_r($results);
But the status=live parameter is not taking effect and all events including drafts are being returned.
Has anyone successfully achieved a list of live events using EventBrite's API and if so, can you advise me how you managed and where I went wrong?
I'm unsure if I just helped you via email, but after troubleshooting I've deducted that this will only return 'live' events if you also pass in 'started' as a status parameter.
Ex.) 'https://www.eventbriteapi.com/v3/users/me/owned_events/?status=live,started'
I hope this helps!
For the benefit of anyone else with a similar problem, the issue was the "Content-Type" header. Remove this, and all is well with the world.

How can I get a unique identifier associated with a meetup access token?

I have implemented a simple api in python to get an OAuth2 access token from a user in meetup. How can I get a unique identifier from that user, using the access token, other than the token itself? For example, if I'm given an access token, how can I get that users email address?
You can make a call to https://api.meetup.com/2/member/self.
PHP example with cURL library:
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, 'https://api.meetup.com/2/member/self');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: bearer ' . $accessToken
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$userData = json_decode($result);
You can get the ID from the user like $userData->id. As far as I know E-mail is not provided by this API call, at least not as a default anyway.
according to the docs here: http://www.meetup.com/meetup_api/docs/2/member/#get you should ask for the e-mail address by passing in the "fields=email" request parameter and this will return the e-mail address only if the following conditions are met:
email: Member's email address, if requested in fields parameter. This item is
only included if the currently authenticated user is the founder of a
Meetup Everywhere in which the member has elected to share an email
address.

How to check whether a username is being used on Twitter without being rate limited?

There are many REST API methods to check if a username is being used on Twitter but as far as I researched all of them are rate limited.
The reason I want this feature is to prevent someone from claiming a username on a website that someone else uses on Twitter, for example someone might claim a celebrity's username and confuse people.
It's impossible to use oauth in this scenario, since the user in this scenario might not be a Twitter user.
[150/hour rate limit is unacceptable. A possible solution would be to use Bing Search API to search for the username? - If Bing Search is not rate limited of course]
Try curl, here is minimal working script in php:
$url = "http://mobile.twitter.com/justinbieber";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($code == 200)
{
echo "He is on twitter";
}
else
{
echo "He is on not twitter";
}
You should query mobile.twitter.com instead of real one, because real one doesn't do HTTP response codes. and few more reasons.

Resources