So I read a couple of posts already regarding this topic and tried some things they mentioned to do to no avail. I am fairly certain I have correctly given my account permission to API calls, but that wasn't the problem. I saw something about signing a request to an AWS search, but I'm not quite sure if that's it or how I would even do it.
This is the code I have.
from amazon.api import AmazonAPI
def get_amazon_link(item):
amazon = AmazonAPI('...AmazonKey', '...SecretKey', '...AssociateTag')
try:
product = amazon.lookup(ItemId='B00GDQ0RMG')
except Exception as e:
print e
print product
Right now the item I'm passing the function is hard coded just to try and get it working. If anyone could help me out that would be awesome.
Make sure you pass the correct region for which your account is registered. More info here.
Related
I'm trying to grab tiles from OpenStreetMap. I learned the syntax of their API. I have an "old way" of doing things, using Requests, and a "new way", which is being used by someone else's github project. I'm trying to use their project, but it's failing for me in one spot. I then put together this short script as a minimal example:
from PIL import Image
import requests
import urllib.request
#A tile we want to grab from Open Street Map
tile_url = "https://a.tile.openstreetmap.org/16/19299/24629.png"
#Old way: Get the bytes via requests.get, then parse as image and save.
old_way = Image.open(requests.get(tile_url,stream=True).raw)
old_way.save("oldway.png")
#New way: use urlretrieve to directly copy the file over to newway.png
destination = "newway.png"
try:
path, response = urllib.request.urlretrieve(tile_url, destination)
except urllib.error.URLError as e:
print("URL error!")
print(e.code)
#Expected behavior: Two identical images are created,
#named oldway.png and newway.png
#Actual behavior: We get oldway, but newway gives a 403 error.
What's going wrong here? What's the difference between these two HTTP GET requests which results in the first one working fine, and the second one giving a 403 error? I've tried digging into the source code of the respective Python libraries, but it turns out to be a pretty long mess of functions calling each other. And of course since it's HTTPS, I can't monitor the network connection to evaluate the raw bytes being transferred and figure things out that way.
Is there something wrong with the user-agent? Something with the headers? Please note that I'm not just trying to solve this problem ("What's the issue? You have a method that works. Ignore the broken one"), but I'm trying to learn about the details here and hoping that this odd edge case can benefit me in the future.
I was just trying to create a bot that uploads a tweet after a time interval (not necessarily regular). However, after a certain amount of tweets my app gets limited and restricted by twitter. Is there a work around for this?
The max number of tweets I've been able to send has been 30. I even tried using sleep() with random time limits but it still doesn't work.
import tweepy
import random
import time
consumerKey=''
consumerSecret=''
accessToken=''
accessTokenSec=''
def OAuth():
try:
auth=tweepy.OAuthHandler(consumerKey,consumerSecret)
auth.set_access_token(accessToken,accessTokenSec)
return auth
except Exception as e:
return None
oauth=OAuth()
api=tweepy.API(oauth,wait_on_rate_limit=True)
tweets=['i love roses','7 is my favourite number', 'Studies are hard','Guess how many donuts I just ate','A cat ran over my foot']
for i in range(40):
num2=random.randint(0,4)
randtime=random.randint(60,120)
api.update_with_media(imglink,+tweets[num2])
print("status uploaded")
time.sleep(randtime)
Same problem, unfortunately Twitter API have restrictions for normal users.
You need to are a company or something else. Twitter need to know how you use the data. There is no way sorry...
Same thing happened to me. You could create a new standalone app (in the overview) and replace the consumer and access tokens with the new ones. It worked for me.
I am trying to find information (description, title, images, aspects, and basically everything) on a product by using a UPC. I managed to do so by using eBay's trading API (GetItem) and productID. However, when I am trying to do it with a UPC I encounter problems. There is not much instructions on the web. I found the function getProductDetails, which is supposed to answer my question:
This is my code:
from ebaysdk.trading import Connection
api = Connection(devid=dev_id, certid=cert_id, appid=app_id, token=token_id, globalId="EBAY-US", config_file=None)
response = api.execute('getProductDetails', {"productDetailsRequest": {"dataset": {"UPC": "#UPCNUMBER"}}})
r = response.dict()
print(r)
However, when I tried to use the same API (trading) I got this error:
ConnectionError: 'getProductDetails: Class: RequestError, Severity: Error, Code: 2, Unsupported API call. The API call "getProductDetails" is invalid or not supported in this release.'
I tried to understand what API exactly I should use, but there is no information on the internet. From the documentation, I can understand that that is a Product API. However, when looking at the different ebaysdk.xxx sub-modules, I don't see any sub-module which fits.
Does somebody know anything about this?
I am very new to the Graph API and trying to write a simple python script that first identifies all pages that a user has liked and all groups that he/she is a part of. To do this, I used the following:
To get the groups he has joined:
API: /{user-id}/groups
Permissions req: user_groups
To get the pages he has liked:
API: /{user-id}/likes
Permissions req: user_likes
and
url='https://graph.facebook.com/'+userId+'/likes?access_token='+accessToken +'&limit='+str(limit)
Now that I can see the id's of the groups in the JSON output, I want to hit them one by one and fetch all content (posts, comments, photos etc.) posted within that group. Is this possible and if yes, how can I do it? What API calls do I have to make?
That's quite a broad question, before asking here you should have give a try searching on SO.
Anyways, I'll tell you broadly how can you do it.
First of all go through the official documentation of Graph API: Graph API Reference.
You'll find each and every API which can be used to fetch the data. For example: /group, /page. You'll get to know what kind of access token with what permissions are required for an API call.
Here are some API calls useful to you-
to fetch the group/page's posts- /{group-id/page-id}/posts
to fetch the comments of a post- {post-id}/comments
to fetch the group/page's photos- /{group-id/page-id}/photos
and so on. Once you'll go through the documentation and test some API calls, the things would be much clear. It's quite easy!
Hope it helps. Good luck!
Here's an example using facepy:
from facepy import GraphAPI
import json
graph = GraphAPI(APP_TOKEN)
groupIDs = ("[id here]","[etc]")
outfile_name ="teacher-groups-summary-export-data.csv"
f = csv.writer(open(outfile_name, "wb+"))
for gID in groupIDs:
groupData = graph.get(gID + "/feed", page=True, retry=3, limit=500)
for data in groupData:
json_data=json.dumps(data, indent = 4,cls=DecimalEncoder)
decoded_response = json_data.decode("UTF-8")
data = json.loads(decoded_response)
print "Paging group data..."
for item in data["data"]:
...etc, dealing with items...
Check the API reference. You should use feed.
You can use /{group-id}/feed to get an array of Post objects of the group. Remember to include a user access token for a member of the group.
Issues using SoundCloud API with python to get user info
I've downloaded the soundcloud library and followed the tutorials, and saw on the soundcloud dev page that user syntax is, for example /users/{id}/favorites.
I just don't know how to use python to query user information. Specifically, i would like to print a list of tracks that a given user liked, (or favorited, but liked would be better).
any help would be greatly appreciated. thanks!
Generally, It's better to mention what you have tried and show some code. It makes it easier for people to help you on Stack Overflow. Regardless maybe looking at SoundCloud's Python wrapper will help you.
You can also do the following :
import soundcloud
token= 'user_access_token'
client = soundcloud.Client(access_token=token)
user_info = client.get('/me')
user_favorites = client.get('/me/favorites')
user_tracks = client.get('/me/tracks')
and so on...
I figured it out, pretty simple just didn't know the exact syntax.
users = client.get('/users', g ='keyword')