Expand Tumblr shortened link - api

I have a Tumblr link like this: http://tumblr.com/XXXXXXXX
In order to communicate with their API I need the hostname of the blog, therefore I need to expand the link to the complete link. Something like: http://blogname.tumblr.com/post/XXXXXX
How can I expand a tumblr shortened link?

Within the Tumblr API, I do not believe it is possible as mentioned by Derek Gottfrid. If you are using it within your app or service you can try looking at the headers.
For example in python, you can use urllib2
import urllib2
tumb = urllib2.urlopen('http://tumblr.com/XXXXXXXX')
print tumb.url
In PHP, you can use the get_headers method
$url = 'http://tumblr.com/XXXXXXXX'
print_r(get_headers($url))

Here's another way to do it in Ruby. It needs to follow tumblr redirection. From http://tmblr.co/XXXXX to http://www.tumblr.com/XXXXX and lastly to the expanded URL. From Net::HTTP documentation:
require 'net/http'
require 'uri'
def get_permalink(uri_str, limit=5)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
response = Net::HTTP.get_response(URI.parse(uri_str))
case response
when Net::HTTPOK then uri_str
when Net::HTTPMovedPermanently
get_permalink(response['location'], limit-1)
when Net::HTTPFound
get_permalink(response['location'], limit-1)
end
end
Hope it helps someone

Related

Github Enterprise Raw URL Gist Unable to Download

I'm able to get a list of gists and their files https://api.git.mygithub.net/users/myuser/gists?per_page=100&page=1 which I found using the docs here: https://docs.github.com/en/free-pro-team#latest/rest/reference/gists#get-a-gist
The files on the gist object have a raw_url. If I fetch the raw_url with the same token, it fails wanting me to authenticate. If I add the header: Accept: application/vnd.github.v3.raw it returns a 406 Not Acceptable. I've references to that header around.
I'm not sure what the scope should be on the token. It seems like it would be the same one I accessed the API. In the UI if you click the raw file it gets a token appended to the url. That token doesn't look like one of the Private tokens mentioned here: https://docs.github.com/en/free-pro-team#latest/github/authenticating-to-github/creating-a-personal-access-token
So what is the format of the HTTP request to download the raw gist?
The raw url needs to have the hostname of gist. changed to raw. and the url path needs to start with /gist/.
Example code in Go fixing it:
url := gistFile.RawUrl
url = strings.Replace(url, "gist.", "raw.", 1)
url = strings.Replace(url, ".net/", ".net/gist/", 1)

What data can I save from the spotify API?

I'm building a website and I'm using the Spotify API as a music library. I would like to add more filters and order options to search traks than the api allows me to so I was wondering what track/song data can I save to my DB from the API, like artist name or popularity.
I would like to save: Name, Artists, Album and some other stuff. Is that possible or is it against the terms and conditions?
Thanks in advance!
Yes, it is possible.
Data is stored in Spotify API in endpoints.
Spotify API endpoint reference here.
Each endpoint deals with the specific kind of data being requested by the client (you).
I'll give you one example. The same logic applies for all other endpoints.
import requests
"""
Import library in order to make api calls.
Alternatively, ou can also use a wrapper like "Spotipy"
instead of requesting directely.
"""
# hit desired endpoint
SEARCH_ENDPOINT = 'https://api.spotify.com/v1/search'
# define your call
def search_by_track_and_artist(artist, track):
path = 'token.json' # you need to get a token for this call
# endpoint reference page will provide you with one
# you can store it in a file
with open(path) as t:
token = json.load(t)
# call API with authentication
myparams = {'type': 'track'}
myparams['q'] = "artist:{} track:{}".format(artist,track)
resp = requests.get(SEARCH_ENDPOINT, params=myparams, headers={"Authorization": "Bearer {}".format(token)})
return resp.json()
try it:
search_by_track_and_artist('Radiohead', 'Karma Police')
Store the data and process it as you wish. But you must comply with Spotify terms in order to make it public.
sidenote: Spotipy docs.

How to get the response content in selenium?

When I open the URL with driver.get(url), how can I get the response content of the page? Please refer to the image for more information.
In a separate post I saw this answer. As per it there is a ticket opened for Selenium.
I'm using Python and Django, but it's actually simple to get the response. I'm using a StaticLiveServerTestCase as my base test for the test. The .get() method on self.client actually returns the response itself. For example:
response = self.client.get(url)
However, it looks like what you're really trying to get is the cookie based on what you're pointing to in the picture. I use Django and the Django test suite to authenticate a user session to be used in the test.
def create_pre_authenticated_session(self, username, url="/"):
user = User.objects.create(username=username)
session = SessionStore()
session[SESSION_KEY] = user.pk
session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
session[HASH_SESSION_KEY] = user.get_session_auth_hash()
session.save()
# to set a cookie we need to first visit the domain.
# 404 pages load the quickest!
self.browser.get(self.live_server_url + '/404_no_such_url/')
self.browser.add_cookie(dict(
name=settings.SESSION_COOKIE_NAME,
value=session.session_key,
secure=False,
path='/',
))
self.browser.get(self.live_server_url + url)
return user
This has some other stuff in it that I borrowed from Percival's Test-Driven Development with Python, but I hope that it can provide some guidance on what you're trying to accomplish.

Get workspace details in podio api

Is there any way to get work space name and URL if the API request is authenticated as app.
Podio::authenticate_with_app($app_id, $app_token);
PodioSpace::get($space_id);
the above code return PodioForbiddenError
Sorry, but the I don't think this is allowed within the scope hierarchy.
Please refer to https://developers.podio.com/authentication/scopes
But, if you only need space name, id, url and couple of other minor details you could still get it by using fields parameter. This is described here: https://developers.podio.com/index/api (scroll down to the end of page).
Here is how I debug it with Ruby:
Podio.client.authenticate_with_app(<app_id>, <app_token>)
app = Podio::Application.find(app_id, {'fields' => 'space.view(full)'})
puts app['space']['name']
puts app['space']['space_id']
puts app['space']['url']

How to retrieve a list of all articles of Fogbugz-wiki that have a certain tag?

Via the Fogbugz REST API I try to get all articles with a certain tag. I wrote some code in python to get it but I got "zero" as result. Here is my code:
import requests
...
some code to log in
...
req_params={"cmd": "search", "token": self.token,"q":"tag:\"my_cool_tag\""}
response = requests.get(req_url, data=req_body, headers=req_header, params=req_params, verify=False)
print (response.text)
as response I got:
...cases count="0"...
Is there a way to get all articles with a certain tag in a list via REST-API and how I can achieve this?
I am using FogBugz Version 8.8.49.0.
Try the search with curl or directly in your web browser to check that it works, then see if you can debug your Python.
In a browser I can successfully query FogBugz Online with something like:
https://<domain>.fogbugz.com/api.asp?token=<token>&cmd=search&q=tag:%22<my_tag>%22
Although I entered quotes around my tag, the browser url encoded them to %22. Obviously <domain>, <token> and <my_tag> should be replaced with your own values.
Your basic parameters look OK, but I haven't used Python so am not sure whether escaping the quotes around the tag translates well to the GET request? Maybe try url encoding "my_cool_tag".