Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to integrate Flickr API? #27

Open
SkippyHo opened this issue May 25, 2018 · 2 comments
Open

Is it possible to integrate Flickr API? #27

SkippyHo opened this issue May 25, 2018 · 2 comments

Comments

@SkippyHo
Copy link

SkippyHo commented May 25, 2018

Hello,

Is it possible to integrate Flickr API instead of Imgur?

Thanks a lot!!

@agusmakmun
Copy link
Owner

Sounds like a great idea @SkippyHo. Can you submit a pull request?

@some1ataplace
Copy link

Maybe try this. I did not test this but maybe it can help someone.

  1. Install the python-flickrapi library by running pip install flickrapi in your terminal.

  2. In your Django project's settings.py file, add the following settings:

FLICKR_API_KEY = 'your_api_key_here'
FLICKR_API_SECRET = 'your_api_secret_here'
  1. In your Django project's urls.py file, add a URL pattern to handle the image upload:
from django.conf.urls import url
from markdownx import urls as markdownx

urlpatterns = [
    # your other URL patterns here
    url(r'^markdownx/flickr/$', 'your_app.views.flickr_upload', name='markdownx_flickr_upload'),
    url(r'^markdownx/', include(markdownx)),
]

  1. In your Django app's views.py file, define a view to handle the image upload:
from django.http import HttpResponse
from flickrapi import FlickrAPI
from markdownx.utils import markdownify

def flickr_upload(request):
    if request.method == 'POST':
        # get the image data from the request
        image_data = request.FILES['image']

        # authenticate with Flickr
        flickr = FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET, format='etree')
        (token, frob) = flickr.get_token_part_one(perms='write')
        if not token:
            raise Exception
  1. Redirect the user to Flickr's authentication page to authorize your app to upload images:
auth_url = flickr.auth_url(perms='write')
return HttpResponseRedirect(auth_url)
  1. After the user has authorized your app, retrieve the access token and secret:
flickr.get_token_part_two((token, frob))
access_token = flickr.token_cache.token.token
access_secret = flickr.token_cache.token.token_secret
  1. Upload the image to Flickr using the access token and secret:
response = flickr.upload(filename=image_data.name, fileobj=image_data, title='My Image', description='Uploaded with django-markdown-editor', auth_token=access_token, auth_secret=access_secret)
photo_id = response.find('photoid').text
  1. Finally, return the URL of the uploaded image to the markdown editor:
image_url = flickr.photos_getSizes(photo_id=photo_id)[0].find('source').attrib['url']
return HttpResponse(markdownify('![My Image]({})'.format(image_url)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants