Get list people you are following on twitter - twitter

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

Related

How to handle the result of a list of future with ReasonML?

I am trying to go over a list of items, cache the URL and then update the URL in the list before drawing it.
However I don't seems to be able to do so.
Any idea?
external cache: option(string) => Js.Promise.t({. "uri": string, "filePath": string }) = "get";
let items = result##data##data->Option.getWithDefault([||]);
let cachedUri = items
->Belt.Array.map(
item =>
cache(item##hosted_video_url)
->FutureJs.fromPromise(Js.String.make)
->Future.flatMapOk(cachedObj => (
{. "hosted_video_url": cachedObj##uri }
)
))
->Belt.Array.toList
->Future.all;
The idea is that you cannot exit a future, so you need to update the state inside the future thing rather than trying to get an equivalent of an asyncio.gather or something similar.
I changed:
setVerticalData(_ => {items-> Js.Array2.sortInPlaceWith((a, b) => {...})});
with
items
->List.fromArray;
->List.map(item =>
cache(item##hosted_video_url)
->FutureJs.fromPromise(Js.String.make)
)
->Future.all
->Future.map(cachedList => {
setVerticalData(_ => {items: cachedList})
})

Sending multiple string parameters to post request in Rails

I am using Net::HTTP::Post to send a request to a pre-determined url, like so:
my_url = '/path/to/static/url'
my_string_parameter = 'objectName=objectInfo'
my_other_string_parameter = 'otherObjectName=otherObjectInfo'
request = Net::HTTP::Post.new(my_url)
request.body = my_string_parameter
However, I know that my_url expects two string parameters. I have both parameters ready (they're statically generated) to be passed in. Is there a way to pass in multiple strings - both my_string_parameter as well as my_other_string_parameter to a post request via Ruby on Rails?
EDIT: for clarity's sake, I'm going to re-explain everything in a more organized fashion. Basically, what I have is
my_url = 'path/to/static/url'
# POST requests made to this url require 2 string parameters,
# required_1 and required_2
param1 = 'required_1=' + 'param1_value'
param2 = 'requred_2=' + 'param2_value'
request = request.NET::HTTP::Post.new(my_url)
If I try request.body = param1, then as expected I get an error saying "Required String parameter 'required_2' is not present". Same with request.body=param2, the same error pops up saying 'required_1' is not present. I'm wondering if there is a way to pass in BOTH parameters to request.body? Or something similar?
Try this.
uri = URI('http://www.example.com')
req = Net::HTTP::Post.new(uri)
req.set_form_data('param1' => 'data1', 'param2' => 'data2')
Alternative
uri = URI('http://www.example.com/')
res = Net::HTTP.post_form(uri, 'param1' => 'data1', 'param2' => 'data2')
puts res.body
For more request like Get or Patch you can refer This offical doc.
You can send it like this.
data = {'params' => ['parameter1', 'parameter2']}
request = Net::HTTP::Post.new(my_url)
request.set_form_data(data)
If your params are string:
url = '/path/to/controller_method'
my_string_parameter = 'objectName=objectInfo'
my_other_string_parameter = 'otherObjectName=otherObjectInfo'
url_with_params = "#{url}?#{[my_string_parameter, my_other_string_parameter].join('&')}"
request = Net::HTTP::Post.new(url_with_params)
If your params are hash It would be easier
your_params = {
'objectName' => 'objectInfo',
'otherObjectName' => 'otherObjectInfo'
}
url = '/path/to/controller_method'
url_with_params = "#{url}?#{your_params.to_query}"
request = Net::HTTP::Post.new(url_with_params)

Post video to Vine on iOS

I have searched this extensively and also looked at unofficial Vine API. Below is the code I see in endpoints file :
def post(videoUrl, thumbnailUrl, description, entities, optionals = {} )
forsquareVenueId = optionals["forsquareVenueId"] || optionals[:forsquareVenueId]; venueName = optionals["venueName"] || optionals[:venueName]; channelId = optionals["channelId"] || optionals[:channelId]
url = (API_URL + "posts") % []
params = { "forsquareVenueId" => forsquareVenueId , "venueName" => venueName , "channelId" => channelId , "videoUrl" => videoUrl , "thumbnailUrl" => thumbnailUrl , "description" => description , "entities" => entities }.reject { |k, v| v.nil? }
api_call "post", url, params, nil
end
From what I have understood, it seems I need to first create a post, then update it using HTTP Put method with video data and thumbnail data. But I am not clear how to populate various fields such as 'entities' in JSON. Need some help on this.

Twitter API call not working

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)

Using result of `JSON.decode` in Rails

So I have an action in my controller that does a get_response to an API:
def memeapi
require "net/http"
require "uri"
#meme = Meme.new(params[:meme])
url = "http://version1.api.memegenerator.net/Instance_Create?username=apigen&password=SECRET&languageCode=en&generatorID=#{#meme.memeid}&imageID=#{#meme.imgid}&text0=#{#meme.text0}&text1=#{#meme.text1}"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
# I want to convert it to the Rails data structure - a hash
result = ActiveSupport::JSON.decode(data)
end
Ok but now I want to get back the information, use it to create another object, but I cant even format the information I am getting, can anyone tell me what I am doing wrong, what am I missing?
I want to be able to access the information from the get_response...
Thank you.
This is the JSON structure
{"success":true,"result":{"generatorID":45,"displayName":"Insanity Wolf","urlName":"Insanity-Wolf","totalVotesScore":0,"imageUrl":"/cache/images/400x/0/0/20.jpg","instanceID":13226270,"text0":"push","text1":null,"instanceImageUrl":"/cache/instances/400x/12/12916/13226270.jpg","instanceUrl":"http://memegenerator.net/instance/13226270"}}
I dont want to save all the fields btw...
result will look something like this after JSON.decode in your code.
{
'success' => true,
'result' => {
"generatorID" => 45,
"displayName" => "Insanity Wolf",
"urlName" => "Insanity-Wolf",
"totalVotesScore" => 0,
"imageUrl" => "/cache/images/400x/0/0/20.jpg",
"instanceID" => 13226270,
"text0" => "push",
"text1" => nil,
"instanceImageUrl" => "/cache/instances/400x/12/12916/13226270.jpg",
"instanceUrl" => "http://memegenerator.net/instance/13226270"
}
}
You have a nested hash (hash as part of a hash) here, which you can access like this:
image_url = result['result']['imageUrl'] # => "/cache/images/400x/0/0/20.jpg"
What you actually want to do with this information, I cannot guess. Maybe you want to update the Meme object you created?
#meme.url = image_url

Resources