Endpoints Example?

61 views
Skip to first unread message

Malachai Frazier

unread,
Aug 5, 2012, 7:20:18 PM8/5/12
to sing...@googlegroups.com
(Relative newbie in APIs)
I'm having trouble finding examples of Singly endpoint examples in actual use. Are there any out there? 

Joshua Kehn

unread,
Aug 5, 2012, 7:27:03 PM8/5/12
to sing...@googlegroups.com
Examples as in existing sites or applications that use it? Or “how-to” style tutorials? 

Best,

–Josh
____________________________________
Joshua Kehn | @joshkehn

On Aug 5, 2012, at 7:20 PM, Malachai Frazier wrote:

(Relative newbie in APIs)
I'm having trouble finding examples of Singly endpoint examples in actual use. Are there any out there? 

--
You received this message because you are subscribed to the Google Groups "Singly API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/singlyapi/-/KB8qYvAQRuMJ.
To post to this group, send email to sing...@googlegroups.com.
To unsubscribe from this group, send email to singlyapi+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/singlyapi?hl=en.

Malachai Frazier

unread,
Aug 5, 2012, 8:10:21 PM8/5/12
to sing...@googlegroups.com
Yessir. I'm looking for something in a "how to work with returned Twitter json objects in the Singly API" kind of example.
--
Malachai Frazier,

Founder of Butterburn LLC.,
Citizen Philanthropist at RLLM

Real Life. Real Music. 
bit.ly/KEJmLB 

Justin Parker

unread,
Aug 5, 2012, 10:05:39 PM8/5/12
to sing...@googlegroups.com
The node.js example app contains an example of returning the 5 latest tweets. (http://github.com/singly/nodejs_express_skeleton). Anything in particular you are looking for? Let us know and we can offer suggestions!

Since you mentioned twitter, here is some information on how to work with the what is returned with /timeline. You'll have to parse the JSON response before you can do anything with it. I don't know what language you're writing your app in, but a google search for "<language> JSON" will be a lot of help. Don't be afraid to ask here if you have any more questions!

assuming obj is the parsed JSON object

Each tweet can be accessed with obj[i] where i is between 0 and limit-1 (the limit default is 20)

obj[i].data.user.screen_name is the user that posted the tweet (change 'screen_name' to 'name' to get the real name)

obj[i].data.text is the contents of the tweet.

Just follow this pattern and look at https://singly.com/twitter and you'll be doing amazing things in no time!


Justin



On Sunday, August 5, 2012 5:10:21 PM UTC-7, Malachai Frazier wrote:
Yessir. I'm looking for something in a "how to work with returned Twitter json objects in the Singly API" kind of example.

On Sun, Aug 5, 2012 at 7:27 PM, Joshua Kehn <jo...@kehn.us> wrote:
Examples as in existing sites or applications that use it? Or “how-to” style tutorials? 

Best,

–Josh
____________________________________
Joshua Kehn | @joshkehn

On Aug 5, 2012, at 7:20 PM, Malachai Frazier wrote:

(Relative newbie in APIs)
I'm having trouble finding examples of Singly endpoint examples in actual use. Are there any out there? 

--
You received this message because you are subscribed to the Google Groups "Singly API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/singlyapi/-/KB8qYvAQRuMJ.
To post to this group, send email to sing...@googlegroups.com.
To unsubscribe from this group, send email to singlyapi+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/singlyapi?hl=en.

--
You received this message because you are subscribed to the Google Groups "Singly API" group.
To post to this group, send email to sing...@googlegroups.com.
To unsubscribe from this group, send email to singlyapi+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/singlyapi?hl=en.

Malachai Frazier

unread,
Aug 5, 2012, 10:29:19 PM8/5/12
to sing...@googlegroups.com
The language should help :) I'm using Sinatra (Ruby). Here is the fun in by main.rb:

get "/home" do
  @title = "ShortJab.me"
  if session[:access_token]
    @self = HTTParty.get(self_url,{
                :query => {:access_token => session[:access_token]}
                }).parsed_response
  end
  @display_name = JSON.generate(@self) do |id|
                      id["i"].data.user.screen_name
                    end

  erb :home
end

Here is the view:

<p> Works! Whats up <%= @display_name %> </p>


I get the huge JSON output but can't figure out how to access "screen_name"

To view this discussion on the web visit https://groups.google.com/d/msg/singlyapi/-/WIjpRuRMSo8J.

To post to this group, send email to sing...@googlegroups.com.
To unsubscribe from this group, send email to singlyapi+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/singlyapi?hl=en.

Kristján Pétursson

unread,
Aug 6, 2012, 2:54:21 PM8/6/12
to sing...@googlegroups.com
It doesn't look to me like `JSON.generate` uses a block: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/json/rdoc/JSON.html#method-i-generate (view source)

Here's a little script I put together to display the latest user/tweet from the Singly API. Is this what you're looking for?

#! /usr/bin/env ruby                                                              
                                                                                  
require 'rubygems'                                                                
require 'httparty'                                                                
                                                                                  
API_BASE = 'https://api.singly.com'                                               
                                                                                  
tweets = HTTParty.get(API_BASE + '/services/twitter/tweets', {                    
  :query => {:access_token => ENV['SINGLY_TOKEN']}                                
})
                                                                                  
tweet = tweets.first                                                             
puts "@#{tweet['data']['user']['screen_name']}: #{tweet['data']['text']}"

Kristján Pétursson

unread,
Aug 6, 2012, 2:59:15 PM8/6/12
to sing...@googlegroups.com
Noticed your code is probably looking at /services/twitter/self (Is that self_url?). Here's a new example hitting that too:

#! /usr/bin/env ruby

require 'rubygems'
require 'httparty'


me = HTTParty.get(API_BASE + '/services/twitter/self', {
  :query => {:access_token => ENV['SINGLY_TOKEN']}
}).first

puts "My screen name is @#{me['data']['screen_name']}"

tweets = HTTParty.get(API_BASE + '/services/twitter/tweets', {
  :query => {:access_token => ENV['SINGLY_TOKEN']}
})

tweet = tweets.first
puts "@#{tweet['data']['user']['screen_name']}: #{tweet['data']['text']}"


Malachai Frazier

unread,
Aug 6, 2012, 3:13:28 PM8/6/12
to sing...@googlegroups.com
Ah-ha! Brilliant! As soon as my masters let me go home from the office, I'm using this strategy.

I eventually figured out that `JSON.generate` was unnecessary for this purpose. 'HTTParty.get' already returns what Ii need :)  

Malachai Frazier

unread,
Aug 6, 2012, 8:44:10 PM8/6/12
to sing...@googlegroups.com
She works! I'm even able to get @image = me['data']['profile_image_url']   :)

Oddly, I can only grab the little pic...

Kristján Pétursson

unread,
Aug 6, 2012, 8:52:27 PM8/6/12
to sing...@googlegroups.com
Ah, we can help with that too!

You can remove the _normal at the end of the image URL to get to the original photo. Or, add ?map=true and we'll put it in me['map']['photo']

me = HTTParty.get(API_BASE + '/services/twitter/self', {
  :query => {
    :access_token => ENV['SINGLY_TOKEN'],
    :map => true
  }
}).first

puts "Original photo: #{me['map']['photo']}"

Malachai Frazier

unread,
Aug 6, 2012, 9:01:29 PM8/6/12
to sing...@googlegroups.com
You've done it again!

Kristján Pétursson

unread,
Aug 6, 2012, 9:04:49 PM8/6/12
to sing...@googlegroups.com
I am APIMan!

Inline image 1

image.png
Reply all
Reply to author
Forward
0 new messages