POST request to API - php

So some quick background: I'm trying to teach myself to code, but right now I'm really a beginner. I'm trying to help out my younger brother's school with setting up a moodle-powered online course system featuring videos of full classes, and I've run into a snag with the school's preferred video host.
Basically, here's my problem:
The guys hosting the videos don't want to allow people to directly link to the videos, instead they built an API they want us to use that takes a POST request, then outputs a new URL, which expires after one use.
I've figured out how to use the API using POSTman or in the terminal
#for example:
# curl -F
# api_key='the api key they gave us' -F
# email='a user's email' -F
# destination='a subdirectory'
# 'the target URL'
What I can't figure out, is how to automate this process so that teachers can input the link to their video on our host's site ('somesite.com/videos/teacherx/') directly in the moodle class editor (if possible), so that whenever a student is taking the class they can click a link that runs the script, does the POST request, and redirects them to the new temporary URL.
In case you can't tell, I have no idea what I'm doing.
Thanks in advance

It sounds like you'll need a text filter - basically search for text and replace it with something else when displaying.
See if your application is listed here : https://moodle.org/plugins/browse.php?list=category&id=7
If not then you will need to write your own filter - the instructions are here https://docs.moodle.org/dev/Filters
Maybe download the code for the screencast filter and see how that works :
https://moodle.org/plugins/view.php?plugin=filter_screencast
Or you can look at the screencast code on github at https://github.com/TechSmith/Moodle-Screencast-Filter

Related

Create Destination Conditioning For Custom Links

Hello. I hope I can be clear enough. So, I have an app where I embed my website, when the url, http://action_share is executed, the app understands it and shares the app. However, when the link is clicked on the web, it takes one to the actual url which doesn't exist. Is there a way to define a destination page for that url if there's no command executed (like the app does), or rather, also create a share command even on the web.
I hope you understand my question.
Edit: I want the link, http://action_share to refer users to a page in my website
Thanks in advance.

Spotify API with basic core PHP

I just need to show my own music on my website. So mine is not an "app" which other users will use. I simply want a PHP script that queries Spotify from time to time, perhaps once every day, and finds if there's a new song added to my playlist. If so, it adds that to my website and shows it on my site.
For this I'd like a very simple script that allows me to authenticate myself in a server side code (which will be executed via cron) and bring back all the tracks in a specific playlist. I'd prefer not to use any library etc, just plain PHP code.
But I'm not sure which 'Authorization API' here I should use. Curl is just for testing, yes? Not for actual code especially with GET as that would be insecure? Would appreciate any pointer to any code sample for this. Thank you.

Crawling play store in core php

I would like to know whether there is any way to crawl the google play store using package url in core php. I want to get the app rating and icon of the particular package url from the play store.
Can anyone help me to do this..??
Check out https://42matters.com/api/lookup They have an open source api that should return just about anything you want and return it in a JSON format. It also has an iOS part as well if you want to crawl that as well!
After you register on the website you will be provided with an Access Token. You need this to build your requests. To get the data on an specific package name, you build the link as this:
https://42matters.com/api/1/apps/lookup.json?access_token=?&p=
NOTE: It must be the PACKAGE NAME, not the title of the app, for example, the package name of Clash of Clans is com.supercell.clashofclans. You can obtain the package name by performing a search through their website as well. That link would be built as such:
https://42matters.com/api/1/apps/search.json?access_token=?q= Where query would be clash of clans!
If you use Google Chrome, give PostMan a try, its great for testing API's!
Hopefully this helps you out, if you need anymore help, let me know and I'll be glad to help you!

Login to website to parse user info

I am trying to figure out how to login into a secure website in order to parse user specific data and I can't really find specific example of how to do so. I would like to write it in PHP but many of searches haven't really turned up anything for that language. I'm familiar with Python and feel like maybe that would be of more use in this scenario. It also seems that many sites have API's specific to that site to login. But searching and using specific API's seems like more work for something I could write once then adapt.
For example: How could I login into stackoverflow programmatically and then parse my profile to fetch the total number of consecutive days i've logged in.
Using Simple_HTML_DOM I have written this which I've used before to parse non-secured html
<?php
include_once('simple_html_dom.php');
$html = file_get_html("http://stackoverflow.com/users/779920/nick");
foreach($html->find('[class=days-visited]') as $e)
echo $e->outertext . '<br>';
?>
But it doesn't work in this case. I'm not sure if this is on the right track but I have tried familirized with POST data using firebug for Chrome but the tool is rather complex to me right now and I'm not exactly sure of how to properly decipher the data I'm given.
Any help would be appreciated.
I think that it depends on exactly what system the page is using for authentication, but here is a snippet I used recently for exactly the same thing. In my case, I simply wanted to download the page:
# An example website
domain = 'http://secure.website.com'
url = domain + '/web/page.html'
# Create a new authentication handler
auth_handler = urllib.request.HTTPBasicAuthHandler()
# Set the login username and password
auth_handler.add_password(None, domain, user='username', passwd='password')
# Create and install a new opener for the handler
opener = urllib.request.build_opener(auth_handler)
urllib.request.install_opener(opener)
# Connect to the page
conn = urllib.request.urlopen(url)
# Read all data on the webpage
page = conn.readall().decode()
# close the connection
conn.close()
I refer you to the urllib documentation (for python3. In python2 it is urllib2). It is reasonably well documented, although it took me a bit of trial and error to figure out the exact steps I needed. Note that the authentication handler only needs to handle to
root you log into (in this case http://secure.website.com). Once you've installed the handler it will recognise any pages belonging to that domain and use the authentication information given. Also remember that this is not all that secure - anyone with access to the code will be able to see your login details.
If you subsequently want to parse the webpage, you can use html.parser (or the python2 version, HTMLParser), or the much more powerful BeautifulSoup.

how to login to another site via PHP

I wanted to find out how to login to another site via PHP... I don't know the proper term for it, but basically, I want a user to be able to enter their login information for another website on mine, and interact with it through mine.Is there any tutorial?
thanks
There are few ways to do the job (actually, you just need to send POST data to the other site).
You can use :
curl (example: http://davidwalsh.name/execute-http-post-php-curl),
stream context (example: http://php.net/manual/en/function.stream-context-create.php),
or directly with sockets (example: http://www.jonasjohn.de/snippets/php/post-request.htm).
curl will do that PHP, cURL post to login to WordPress
but you will need that installed on the server which is sometimes not an option. There is however loads of scripts that can do the same thing as curl without the curl libs installed, eg: cakephp's HttpSocket class
as already stated, Curl will do that.
But you can also check out this PHP Class that makes everything easier and gives you a lot of automation out of the Box
Including Prefilling of CSRF Token, finding of all input fields, retrieving of details from the designated site. etc
the class can be found Here. Crawl Engine

Categories