Flickr API: getInfo on Guest Pass photos? - flickr

So, Flickr Guest Pass URLs are in the following format:
www.flickr.com/x/t/[numericID]/gp/[userID]/[alphanumericID]
Now if I try an API call of the following form:
API_KEY = 'myapikey'
PHOTO_ID = '[numericID]'
SECRET = '[alphanumericID]'
url = 'http://api.flickr.com/services/rest/?method=flickr.photos.getInfo' +
'&api_key=%s&photo_id=%s&secret=%s' % (API_KEY, PHOTO_ID, SECRET)
I do get some photo information back, but for completely the wrong photograph!
It may be relevant that the photo ID in my Guest Pass starts "00": in the info returned by the API, the initial zeros have been chopped off.
Am I supplying the right information to getInfo()?

Figured it out in the end. The Photo ID is in the URL that the Guest Pass resolves to. The secret is in the URL of the jpeg of the photo itself.
So, for example, on a photo:
flickr.com/curiouskiwi/5203020393
The photo ID is the final part of the URL. If you view the photo, you find that the JPG of the URL is
farm6.static.flickr.com/5045/5203020393_f41c8d7fe7_z.jpg
And from that, you know the secret is f41c8d7fe7.

Related

Facebook Python SDK - GET events

I am a newbie working with facebook python sdk. I found this file that enabled me to obtain event data from my facebook business page.
However, I am unable to fetch all of the fields I need. The missing field I am unable to obtain is the event videos. I am unable to retrieve the video source or video_url for the video that was posted with the event.
I have tried many different variations of fields =
to no avail. Thank You
import facebook
import requests
def some_action(post):
""" Here you might want to do something with each post. E.g. grab the
post's message (post['message']) or the post's picture (post['picture']).
In this implementation we just print the post's created time.
"""
print(post["id"])
# You'll need an access token here to do anything. You can get a temporary one
# here: https://developers.facebook.com/tools/explorer/
access_token = "My_Access_Token"
# Look at Bill Gates's profile for this example by using his Facebook id.
user = "397894520722082"
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'posts')
print(graph.get_object(id=397894520722082,
fields='events{videos,id,category,name,description,cover,place,start_time,end_time,interested_count,attending_count,declined_count,event_times,comments}'))
# Wrap this block in a while loop so we can keep paginating requests until
# finished.
while True:
try:
# Perform some action on each post in the collection we receive from
# Facebook.
[some_action(post=post) for post in posts["data"]]
# Attempt to make a request to the next page of data, if it exists.
posts = requests.get(posts["paging"]["next"]).json()
except KeyError:
# When there are no more pages (['paging']['next']), break from the
# loop and end the script.
break

How to send accessToken in Detect Intent Text API in Dialogflow

I'm developing my chatbot backend using detect intent API in Python, once the intent recognized, it goes to my webhook and gets the appropriate data.
here is my detectIntent code to get data from text
def detect_intent_texts(project_id, session_id, text, language_code='en-US'):
session_client = dialogflow.SessionsClient().from_service_account_file(
'my_service_account_json.json')
session = session_client.session_path(project_id, session_id)
print('Session path: {}\n'.format(session))
text_input = dialogflow.types.TextInput(text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(session=session, query_input=query_input)
data = MessageToDict(response.query_result)
print (json.dumps(data, indent=4))
response = parse_response(data)
return response
How can I sent access_token with it so that my webhook can identify
which user is accessing the bot
P.S. my webhook is looking for an access token in this path
req.get("originalDetectIntentRequest").get("payload").get("user").get("accessToken")
Everything under the "payload" attribute is platform dependent. The Assistant platform puts user information under here, for example, and this is what your webhook is currently trying to process.
If you wanted to put the access token in the same place, you can pass a query_params named parameter to the call to detect_intent() along with the text you're querying, and anything else that may be relevant. (Reference) That parameter can be a dict and, if so, has to have the same field names as a QueryParameters object.

Response URL different from initial browser URL

Im getting a different URL from what was initially displayed when tried on a browser
Facebook's docs say that a
Login Request
should have a format like this so using requests and urllib.parse I tried getting the response URL
import requests, facebook, logging
# REQUIRED AUTHENTICATION PARAMS
APP_ID = '1976346389294466'
APP_SECRET = '*************************'
REDIRECT_URI = 'https://www.facebook.com/connect/login_success.html/'
logging.basicConfig(level=logging.DEBUG)
perms = ['manage_pages','publish_pages']
fb_login_url = facebook.auth_url(app_id=APP_ID, canvas_url=REDIRECT_URI, perms=perms)
logging.debug("-----LOGIN URL:" + fb_login_url)
response = requests.get(fb_login_url, params={'response_type':'token'}, allow_redirects=True)
try:
response.raise_for_status()
except Exception as exec:
print("%(There was a problem)s" % (exec))
response = requests.get(response.url)
logging.debug("-----Response URL: "+response.url)
I'm expecting a Expected Return URL in the format of
https://www.facebook.com/connect/login_success.html#
access_token=ACCESS_TOKEN...
However, I'm only getting the correct response when I use a browser, on my program the response returns a URL of an entirely different format
https://www.facebook.com/login.php?skip_api_login=1&api_key=xxxxxxxxx&signed_next=1&next=https%3A%2F%2Fwww.facebook.com%2Fv2.11%2Fdialog%2Foauth%3Fredirect_uri%3Dhttps%253A%252F%252Fwww.facebook.com%252Fconnect%252Flogin_success.html%252F%26scope%3Dmanage_pages%252Cpublish_pages%26response_type%3Dtoken%26client_id%xxxxxxxxxxx%26ret%3Dlogin%26logger_id%xxxxxxxxxxxxxxx&cancel_url=https%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html%2F%3Ferror%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%23_%3D_&display=page&locale=en_US&logger_id=xxx-xxxxx-xxxxx-xxxxxxxx
When I GET from the last redirect url from response.history,
the response returns a url to itself, so I'm not sure how to go about capturing
the initial value of the url such as when I use the browser
the thing is, Im not looking for anything else from the response besides the URL itself.
Additional Notes:
-in the browser after getting the response url I think javascript also changes the url to blank after a brief moment for security reasons
-When I enter the wrong formatted url to the browser, it redirects to the right value so is there something thats handling the response differently when I'm using the browser. If so, how do grab the right url?
Simply put
When I enter fb_login_url in browser I get...
https://www.facebook.com/connect/login_success.html#access_token=ACCESS_TOKEN...
which is what I want, but
when I do it in the app with requests...
either with requests.get(fb_login_url).url
OR (because of a 303) something like
for r in response.history:
requests.get(r.url).url
i get the wrong url which is
https://www.facebook.com/login.php?skip_api_login=1&api_key=xxxxxxxxx&signed_next=1&n....

Get wrong parameter from get method in nodejs

I'm trying to send get method request and want to pass value in URL.
Like my api look like
app.get('/api/getlocation/:customerName', customer.getlocation);
For call this I wrote in postman
localhost:8080/api/getlocation/:customerName=kumbhani
For test
var customerName = req.params.customerName;
console.log('name', customerName); // =kumbhani
It returns name with = sign - I want only kumbhani
The colon character in the path in Express has a special meaning: whatever you put in the URL after getLocation/ will be put in req.params.customerName.
This means in Postman, you should actually call this URL:
localhost:8080/api/getlocation/kumbhani
→ See related question.

Generate gmail-attachment url to view

I'm working on project which can access all the pictures in g-mail.I've tried the G-mail API using node which can fetch all required attachments.But that requires to download the whole image.I can access the attachment id and message id using the API.Is there any way to generate the url of attachment (to view) so that i can provide a link to the required image from my project.
I actually found this related issue, Issue #134, and you may want to try the suggested solution.
You may fetch email attachments using this:
https://mail.google.com/mail/u/0/?ui=2&ik={ik_value}&view=att&th={message_id}&attid=0.{atachment_index}&disp=safe&zw
wherein, attachmment_index is just the index of the attachment. If there are 3 attachments and you want to get the 3rd file, the index value will be 3. This URL is a 302 header that acts like a link shortener for the download file. Opening this link will lead you to the attachment data
var ik = gmail.tracker.ik;
var id = gmail.get.email_id();
var aid = "1"; // gets the first attachment
var url = "https://mail.google.com/mail/u/0/?ui=2&ik=" + ik + "&view=att&th=" + id + "&attid=0." + aid + "&disp=safe&zw";
console.log(url);

Resources