Hi Friends i am trying to run twitter apis to get tweets for a hashtag using below code. When i tried get the user timeline it's not giving any error for authentication but when it tried to search for tweets which contains hahstag it's giving authentication error.
$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$token_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$consumer_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$host = 'api.twitter.com';
$method = 'GET';
$path = '/1.1/statuses/user_timeline.json'; // api call path
$query = array( // query parameters
'screen_name' => 'twitterapi'
);
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_token' => $token,
'oauth_nonce' => (string)mt_rand(), // a stronger nonce is recommended
'oauth_timestamp' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_version' => '1.0'
);
$oauth = array_map("rawurlencode", $oauth); // must be encoded before sorting
$query = array_map("rawurlencode", $query);
$arr = array_merge($oauth, $query); // combine the values THEN sort
asort($arr); // secondary sort (value)
ksort($arr); // primary sort (key)
// http_build_query automatically encodes, but our parameters
// are already encoded, and must be by this point, so we undo
// the encoding step
$querystring = urldecode(http_build_query($arr, '', '&'));
$url = "https://$host$path";
// mash everything together for the text to hash
$base_string = $method."&".rawurlencode($url)."&".rawurlencode($querystring);
// same with the key
$key = rawurlencode($consumer_secret)."&".rawurlencode($token_secret);
// generate the hash
$signature = rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));
// this time we're using a normal GET query, and we're only encoding the query params
// (without the oauth params)
$url .= "?".http_build_query($query);
$url=str_replace("&","&",$url); //Patch by #Frewuill
$oauth['oauth_signature'] = $signature; // don't want to abandon all that work!
ksort($oauth); // probably not necessary, but twitter's demo does it
// also not necessary, but twitter's demo does this too
function add_quotes($str) { return '"'.$str.'"'; }
$oauth = array_map("add_quotes", $oauth);
// this is the full value of the Authorization line
$auth = "OAuth " . urldecode(http_build_query($oauth, '', ', '));
echo $auth;exit;
// if you're doing post, you need to skip the GET building above
// and instead supply query parameters to CURLOPT_POSTFIELDS
$options = array( CURLOPT_HTTPHEADER => array("Authorization: $auth"),
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
// do our business
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json);
echo "<pre>";print_r($twitter_data);
When i run this code i am successfully able to get the user time line so i wnt for next step to get tweets for a particular hashtag by chnaging code like below
$host = 'api.twitter.com';
$method = 'GET';
$path = '/1.1/search/tweets.json'; // api call path
$query = array( // query parameters
'q' => '#Polls2013'
);
But now it's giving a weird error like below.
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => Could not authenticate you
[code] => 32
)
)
)
The query you are posting for search should be url encoded in the manner specified by twitter,
See this documentation (https://dev.twitter.com/docs/auth/percent-encoding-parameters)
Related
I keep getting an error: "RestException: [HTTP 400] Unable to create record: The 'To'..."
when trying to use a variable - see below, example = $user_phone_number = "+13334445555"
------------------------------------------------------------
$client = new Client($account_sid, $auth_token);
$client->messages->create(
// Where to send a text message (your cell phone?)
$user_phone_number,
array(
'from' => $twilio_number,
'body' => $MsgBody
)
);
------------------------------------------------------------
this is how i am post in data to server
var request = new http.MultipartRequest("POST", uri);
request.headers.addAll(headers);
request.fields['property_id'] = property_id; //value from textcontroller
request.fields['unit_id'] = unitlist; //value from textcontroller
request.fields['tenant_name'] = tenant_name; //value from textcontroller
request.fields['additional_terms'] = addistiona_tems;//value from textcontroller
var stream = new http.ByteStream(DelegatingStream.typed(file.openRead()));
var length = await file.length();
var tenantimage = new http.MultipartFile('Tenant_image', stream, length,
filename: basename(file.path));
request.files.add(tenantimage);
var response = await request.send();
this is my result when i return sending value as response
Array
(
[property_id] => 2
[unit_id] => 1463
[tenant_name] => aqws
[additional_terms] => awedswer
)
but i want achieve as "unit_id" and "additional_terms" as array?
like this
Array
(
[property_id] => 2
[unit_id] => Array
(
[0]
)
[tenant_name] => aqws
[additional_terms] => Array
(
[0]=> awedswer
[1]=> bilk
)
)
try this:-
request.fields['additional_terms'] = "[{"shop_id":"1","product_id":1,"unit_price":188.0,"quantity":1,"discounted_price":0.0}]"
I am trying to implement basic transaction based queries using Jadell's Neo4jPHP.
Here is my code:
$transaction = $client->beginTransaction();
$query = new Query($client, "CREATE UNIQUE (u:users {email})-[r:visited {'time':'1425283200'}]->(e:halls {hallId}) RETURN r", array('email' => array('email' => 'test#test.com'), 'hallId' => array('hallId' => 1234)));
$result = $transaction->addStatements($query);
$transaction->commit();
I am getting an error:
[message] => Invalid input ''': expected whitespace, a property key
name, '}', an identifier or UnsignedDecimalInteger (line 1, column
52)\n
Any clues as to what is going wrong here?
UPDATE
I tried the following (removed parameters) and still getting an error:
$transaction = $client->beginTransaction();
$query = new Query($client, "CREATE UNIQUE (u:users {'email':'" . $email . "'})-[r:visited]->(e:halls {'hallId':'" . $hallId . "'}) RETURN r");
$result = $transaction->addStatements($query);
$transaction->commit();
Getting an error:
[message] => Unable to deserialize request: Can not deserialize
instance of java.util.LinkedHashMap out of START_ARRAY token\n
This should work.
Use query parameters instead of string concatenation
$transaction = $client->beginTransaction();
$cypher="CREATE UNIQUE (u:users {email:{email}})-[r:visited]->(e:halls {hallId:{hallId}}) RETURN r";
$query = new Query($client,$cypher,array('email'=>$email,'hallId'=>$hallId));
$result = $transaction->addStatements($query);
$transaction->commit();
I have one gremlin query in which I used cap().next()
and Everyman\Neo4j\Query\ResultSet Object is
...
[data:protected] => Array
(
[v[1079]] => Array
(
[0] => 14
)
[v[1082]] => Array
(
[0] => 25
)
[v[1016]] => Array
(
[0] => 5
)
[v[1078]] => Array
(
[0] => 10
)
[v[1081]] => Array
(
[0] => 17
)
)
...
how to get that array?
$result[0][0] is not working.
To iterate ResultSets use
foreach ($result as $row) {
echo $row['x']->getProperty('your_property') . "\n";
}
or with scalar values in column y
foreach ($result as $row) {
echo $row['x']->getProperty('your_property') . ": " . $row['y'] ."\n";
}
It would be nice to have the original gremlin query thought to see what you are returning from it.
see github
IS it possible to something like this:
http://api.twitter.com/1/statuses/followers/xxxxxx.json
but instead of list of people following you, list of people you are following?
Looks like this is what you need:
https://api.twitter.com/1.1/friends/ids.json?id=:screen_name_or_user_id
https://dev.twitter.com/docs/api/1.1/get/friends/ids
Once you have the list of ID's returned, you can look them up by passing them as a comma delimited list to another API call:
http://api.twitter.com/1.1/users/lookup.json?user_id=[comma delimited list goes here]
https://dev.twitter.com/docs/api/1.1/get/users/lookup
You could use this:
https://api.twitter.com/1/friends.json?screen_name=bitboxer
that way you don't have to do two calls for id and than for details.
The new 1.1 URL you need to call is https://api.twitter.com/1.1/friends/ids.json
Full documentation is at https://dev.twitter.com/docs/api/1.1/get/friends/ids.
require_once('tmhOAuth.php');
require_once('tmhUtilities.php');
$profile_username = "abcdefg"; //twitter username
$oauth_access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //Your access token
$oauth_access_token_secret = "YYYYYYYYYYYYYYYYYYYYYYYYYY"; //Your access token secret
$consumer_key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; //Your key
$consumer_secret = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"; //Your secret key
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'user_token' => $oauth_access_token,
'user_secret' => $oauth_access_token_secret,
'curl_ssl_verifypeer' => false
));
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/friends/ids'),
array(
'screen_name' => $profile_username,
'count' => '10'
)
);
$response = $tmhOAuth->response['response'];
$following_ids = json_decode($response, true);
print_r($following_ids);