I'm trying to get only self media.
/users/self/feed --> this return user follow feeds
/users/self/media/recent --> return only recent post
I want to get all self media with this parameters, count=10&max_id=?
Use this API with your {user-id}:
https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id=YOUR-CLIENT_ID
this call will return max of 20 pics, then use the pagination.next_url in the API response to make the next API call to get the next 20 photos and so on...
Related
I'm currently trying to build a project that requires me to read data from a website (OpenSea marketplace). When I go to the page, it sends a POST request to an API (in pic 1), I want to access the data it returns (in pic 2) in my NodeJS/TypeScript project.
Is there maybe an API that can do this or is it not even possible?
Pic 1 (I'm trying to access the graphql/ request):
Pic 2 (This is the data I'm trying to get into my code):
you can hijack the XMLHttpRequest and fetch functions. unconventional, but it would work
Based on the comment I placed, a small function can be used on the client side to do such
function listen(fn){
//this line simply adds functions to call in an array based on setup below
if(listen.prototype.arguments){listen.prototype.arguments.push(fn)}
//below is setup(functions hijacked so services that use them report to this too)
listen.prototype.arguments=[] //array of functions to call
let original1=XMLHttpRequest.prototype.send, original2=fetch
function replace1(){
let toReturn=original1.bind(this)(...arguments)
this.addEventListener("load",res=>fn(this.responseText))
return toReturn
}
function replace2(){
let toReturn=original2.bind(this)(...arguments)
toReturn.then(res=>res.text().then(fn))
return toReturn
}
Object.defineProperty(XMLHttpRequest.prototype,"send",{value:replace1})
Object.defineProperty(window,"fetch",{value:replace2})
}
//example usage
let socket=some_Web_Socket_Your_Backend_To_Handle_This_Data
//perhaps this is not the most elaborate example but I hope the point is understood
listen(socket.send.bind(socket))
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
I have a small form interface where users can add the amount of money they want to load into their account. Users have to load a minimum amount of money. So I need to reject if users put an amount less then certain amount (ie. 50 USD).
I have js validation on place for the form for minimum load. Users put the desired amount then click checkout. After the checkout process stripe js api returns with a token. Token with other data (like amount, currency) are sent to server.
Now I need to validate the amount in the server. I can check the amount and print error message if it does not validate. The token that stripe js api created will remain unused if the validation is rejected.
My question is, what are the problems that can arise if I keep the token unused?
So actually, you don't need to validate on your server. If you attempt to call the Create a Charge API Endpoint with a value less than the minimum (in any currency) Stripe will simply raise an error (400 Bad Request).
Example in Python:
>>> stripe.Charge.create(amount=49, currency="usd", source="tok_visa")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/lib/python2.7/site-packages/stripe/api_resources/abstract/createable_api_resource.py", line 17, in create
response, api_key = requestor.request('post', url, params, headers)
File "~/lib/python2.7/site-packages/stripe/api_requestor.py", line 153, in request
resp = self.interpret_response(rbody, rcode, rheaders)
File "~/lib/python2.7/site-packages/stripe/api_requestor.py", line 365, in interpret_response
self.handle_error_response(rbody, rcode, resp.data, rheaders)
File "~/lib/python2.7/site-packages/stripe/api_requestor.py", line 178, in handle_error_response
raise err
stripe.error.InvalidRequestError: Request req_xxx: Amount must be at least 50 cents
I followed the docs for the vimeo node.js api to upload a file. It's quite simple and I have it working by running it directly in node, with the exception that it requires me to pass the full path of the file I want to upload. Code is here:
function uploadFile() {
let file = '/Users/full/path/to/file/bulls.mp4';
let video_id; //the eventual end URI of the uploaded video
lib.streamingUpload(file, function(error, body, status_code, headers) {
if (error) {
throw error;
}
lib.request(headers.location, function (error, body, status_code, headers) {
console.log(body);
video_id = body.uri;
//after it's done uploading, and the result is returned, update info
updateVideoInfo(video_id);
});
}, function(upload_size, file_size) {
console.log("You have uploaded " +
Math.round((upload_size/file_size) * 100) + "% of the video");
});
}
Now I want to integrate into a form generated in my react app, except that the result of evt.target.files[0] is not a full path, the result is this:
File {name: "bulls.mp4", lastModified: 1492637558000, lastModifiedDate: Wed Apr 19 2017 14:32:38 GMT-0700 (PDT), webkitRelativePath: "", size: 1359013595…}
Just for the sake of it, I piped that into my already working upload function and it didn't work for the reasons specified. Am I missing something? If not I just want to clarify what I actually have to do then. So now I'm looking at the official Vimeo guide and wanted to make sure that was the right road to go down. See: https://developer.vimeo.com/api/upload/videos
So if I'm reading it right, you do several requests to achieve the same goal?
1) Do a GET to https://api.vimeo.com/me to find out the remaining upload data they have.
2) Do a POST to https://api.vimeo.com/me/videos to get an upload ticket. Use type: streaming if I want a resumable upload such as those provided by the vimeo streamingUpload() function
3) Do a PUT to https://1234.cloud.vimeo.com/upload?ticket_id=abcdef124567890
4) Do a PUT to https://1234.cloud.vimeo.com/upload?ticket_id=abcdef124567890 but without file data and the header Content-Range: bytes */* anytime I want to check the bytes uploaded.
Sound right? Or can you simply use a form and I got it wrong somewhere. Let me know. Thanks.
There's some example code in this project that might be worth checking out: https://github.com/websemantics/vimeo-upload.
Your description is mostly correct for the streaming system, but I want to clarify the last two points.
3) In this step, you should make a PUT request to that url with a Content-Length header describing the full size of the file (as described here: https://developer.vimeo.com/api/upload/videos#upload-your-video)
4) In this step, the reason you are checking bytes uploaded is if you have completed the upload, or if your connection in the PUT request dies. We save as many bytes possible, and we will respond to the request in step 4. with how many bytes we received. This lets you resume step 3 where you left off instead of at the very beginning.
For stability we highly recommend the resumable uploader, but if you are looking for simplicity we do offer a simple POST uploader that uses an HTML form. The docs for that are here: https://developer.vimeo.com/api/upload/videos#simple-upload
I am trying to return all the attachments in a project using the basecamp api call documented here:
https://github.com/basecamp/bcx-api/blob/master/sections/attachments.md
The Basecamp documentation says that you can do this in this way...
https://basecamp.com/1234567/api/v1/projects/1234567/attachments.json
Which will return the top 50 results. And which is does :)
But, I have more than 50 results.
So, the documentation says:
We will return 50 attachments per page. If the result set has 50 attachments, it's your responsibility to check the next page to see if there are any more attachments -- you do this by adding &page=2 to the query, then &page=3 and so on.
So, I have tried:
https://basecamp.com/1234567/api/v1/projects/1234567/attachments.json&page=2
But when I try this I get an error:
HTTP/1.1 415 Unsupported Media Type - Only application/json requests are accepted. Check out 'No XML, just JSON' on https://github.com/37signals/bcx-api
Am I reading the instructions wrong? Sure that call should work?
Any help would be greatly appreciated.
Apologies.
I should have spotted it... the documentation says "&" when it should say "?"
The call should be
https://basecamp.com/1234567/api/v1/projects/1234567/attachments.json?page=2