How to get author information from Medium.com posts

I was able to get all the basic information about a medium.com post via JSON using file_get_contents("https://medium.com/publication_name/latest?format=json");

, but is there a way to get the name and photo of the author of the posts?

+3


source to share


1 answer


Given a JSON payload that resembles this:

{
    "payload": {
        "posts": [
            {
                "creatorId": "foobar",
                "title": "How to foo your bars"
            }
        ],
        "references": {
            "User": {
                "foobar": {
                    "userId": "foobar",
                    "name": "Senor Foobar",
                    "imageId": "baz.jpg"
                }
            }
        }
    }
}

      

creatorId

for the message also exists in references

User

. In this example, I used id foobar

. With this key, you can get the author name and file name for the author's photo.



Translating the file name of the author's photo into a URL may require additional work. Current CDN https://cdn-images-1.medium.com/fit/c/60/60/

, so the full url will be https://cdn-images-1.medium.com/fit/c/60/60/foobar.jpg

. This CDN is likely to change over time, so this URL is not absolute.

CDN information is not available in the JSON payload and was found by checking the source for the sample average article.

0


source







All Articles