MediaFire

From Christoph's Personal Wiki
Revision as of 21:29, 27 May 2015 by Christoph (Talk | contribs)

Jump to: navigation, search

MediaFire is a file hosting, file synchronization, and cloud storage service.

MediaFire API

  • Step #1: Create environment variables:
$ MF_ENDPOINT="https://www.mediafire.com/api/1.3"
$ MF_EMAIL=<YOUR_MEDIAFIRE_ACCOUNT_EMAIL>
$ MF_PASSWORD=<YOUR_MEDIAFIRE_ACCOUNT_PASSWORD>
$ MF_APP_ID=<YOUR_MEDIAFIRE_APPLICATION_ID>
$ MF_API_KEY=<YOUR_MEDIAFIRE_API_KEY>
$ MF_SIGNATURE=`python -c "import hashlib;print(hashlib.sha1('${MF_EMAIL}${MF_PASSWORD}${MF_APP_ID}${MF_API_KEY}')).hexdigest()"`
$ MF_QUERY_PARAMS="email=${MF_EMAIL}&password=${MF_PASSWORD}&application_id=${MF_APP_ID}&signature=${MF_SIGNATURE}"
$ curl -s "${MF_ENDPOINT}/user/get_session_token.php?${MF_QUERY_PARAMS}&response_format=json" |\
    python -mjson.tool
# RESPONSE:
{
    "response": {
        "action": "user/get_session_token",
        "current_api_version": "1.3",
        "ekey": "<REDACTED>",
        "pkey": "<REDACTED>",
        "result": "Success",
        "session_token": "<REDACTED>"
    }
}
  • Grab your session token (144 alphanumeric string of characters; valid for 10 minutes) from the response above or set it like so:
$ MF_TOKEN=`curl -s "${MF_ENDPOINT}/user/get_session_token.php?${MF_QUERY_PARAMS}&response_format=json"|\
            python -c 'import sys,json;data=json.loads(sys.stdin.read());print data["response"]["session_token"]'`
  • Get user's basic account information:
$ curl -s "${MF_ENDPOINT}/user/get_info.php?session_token=${MF_TOKEN}&response_format=json" | python -mjson.tool
# RESPONSE:
{
    "response": {
        "action": "user/get_info",
        "current_api_version": "1.3",
        "result": "Success",
        "user_info": {
            "bandwidth": "0",
            "base_storage": "16106127360",
            "birth_date": "",
            "bonus_storage": "39728447488",
            "created": "2010-11-22",
            "display_name": "Bob Brown",
            "ekey": "<REDACTED>",
            "email": "bob@example.com",
            "facebook": {
                "linked": "no"
            },
            "first_name": "Bob",
            "gender": "Male",
            "gmail": {
                "linked": "no"
            },
            "last_name": "Brown",
            "location": "",
            "one_time_key_request_max_count": "10",
            "options": "0",
            "premium": "no",
            "storage_limit": "55834574848",
            "storage_limit_exceeded": "no",
            "tos_accepted": "",
            "twitter": {
                "linked": "no"
            },
            "used_storage_size": "123456789",
            "validated": "yes",
            "website": "http://www.example.com"
        }
    }
}
$ echo 55834574848/1024^3 | bc -l  # => storage_limit = 52 GB
$ curl -s "${MF_ENDPOINT}/folder/get_content.php?session_token=${MF_TOKEN}&content_type=folders&response_format=json" | python -mjson.tool
# RESPONSE:
{
    "response": {
        "action": "folder/get_content",
        "asynchronous": "no",
        "current_api_version": "1.3",
        "folder_content": {
            "chunk_number": "1",
            "chunk_size": "100",
            "content_type": "folders",
            "folders": [
                {
                    "created": "2014-02-01 16:30:44",
                    "description": "",
                    "dropbox_enabled": "no",
                    "file_count": "15",
                    "flag": "2",
                    "folder_count": "0",
                    "folderkey": "<REDACTED>",
                    "name": "foobar",
                    "privacy": "public",
                    "revision": "50"
                }
            ],
            "more_chunks": "no"
        },
        "result": "Success"
    }
}

External links