Esempio n. 1
0
def linkedin_oauth_step2(request):
    oauth_token_1 = request.GET['oauth_token']
    oauth_verifier_1 = request.GET['oauth_verifier']

    #	print "Storing oauth verifier in session",  " Request Token: ", oauth_token_1, "Oauth Verifier: ", oauth_verifier_1
    request.session["session_linkedin_oauth_token"] = oauth_token_1
    request.session["session_linkedin_oauth_verifier"] = oauth_verifier_1

    rts_session = request.session.get("session_linkedin_request_token_secret")
    #	print "Request token secret from session: ", rts_session

    DUMMY_CALLBACK_URL = SITE_URL

    # Call back url in this step2 is just a dummy and is not used
    api = linkedin.LinkedIn(LINKEDIN_CONSUMER_KEY, LINKEDIN_CONSUMER_SECRET,
                            DUMMY_CALLBACK_URL)

    result = api.access_token(request_token=oauth_token_1,
                              request_token_secret=rts_session,
                              verifier=oauth_verifier_1)

    #	print "Storing Access Token in session",  " Access Token: ", api._access_token, "Access Token Secret : ", api._access_token_secret
    request.session["session_linkedin_access_token"] = api._access_token
    request.session[
        "session_linkedin_access_token_secret"] = api._access_token_secret

    redirectURL = request.session.get("session_linkedin_oauth_callingurl")

    #	print "Redirecting back to URL to fetch linkedin data: ", redirectURL
    return HttpResponseRedirect(redirectURL)
Esempio n. 2
0
def lilogin(request):
    liApi = linkedin.LinkedIn('d4sg4uq23heb', 'CECqmTcwYr9GZod5',
                              'http://creeply.dev:8000/linkedin/login')
    liApi.access_token(
        request_token=request.user.liProfile.request_token.encode('utf8'),
        request_token_secret=request.user.liProfile.request_token_secret.
        encode('utf8'),
        verifier=request.GET['oauth_verifier'])
    liProfile = liApi.get_profile()
    t = loader.get_template("profile.html")
    c = Context(liProfile)
    return HttpResponse(t.render(c))
Esempio n. 3
0
def linkedin_oauth_step1(request):
    api = linkedin.LinkedIn(LINKEDIN_CONSUMER_KEY, LINKEDIN_CONSUMER_SECRET,
                            LINKEDIN_OAUTH_STEP2_URL)
    result = api.request_token()
    #	print "LinkedIn Roquest Token: ", api._request_token
    #	print "LinkedIn Roquest Token Secret: ", api._request_token_secret

    request.session[
        "session_linkedin_request_token_secret"] = api._request_token_secret
    redirectURL = api.get_authorize_url(request_token=api._request_token)
    #	print "RedirectURL: ", redirectURL

    return HttpResponseRedirect(redirectURL)
Esempio n. 4
0
    def set_up_class(cls, gae):
        cls._gae = gae
        cls.api = linkedin.LinkedIn(API_KEY, SECRET_KEY, RETURN_URL, gae)
        cls.api.request_token()

        print "----------------"
        print "Go to this address please and fill in the details"
        print cls.api.get_authorize_url()
        print "----------------"
        
        result = []
        httpd = cls._create_http_server(result)
        httpd.handle_request()
        httpd.server_close()
        cls.api._verifier = result[0]
        cls.api.access_token()
Esempio n. 5
0
def oauthDance(key, secret, return_url):
    api = linkedin.LinkedIn(key, secret, return_url)
    result = api.requestToken()
    if not result:
        print >> sys.stderr, api.requestTokenError()
        return None

    authorize_url = api.getAuthorizeURL()

    webbrowser.open(authorize_url)

    oauth_verifier = raw_input('PIN number, bro: ')

    result = api.accessToken(verifier=oauth_verifier)

    if not result:
        print >> sys.stderr, 'Error: %s\nAborting' % api.getRequestTokenError()
        return None

    return api
    def __init__(self,
                 request,
                 post_authorize_url=None,
                 test_data=None,
                 token_timeout=None):
        self.request = request

        if token_timeout is None:
            self.token_timeout = self.ONE_MINUTE
        else:
            self.token_timeout = token_timeout

        api_key = settings.LINKED_IN_API_KEY
        secret_key = settings.LINKED_IN_SECRET_KEY

        if test_data is not None:
            api = TestLinkedInApi(api_key, secret_key, post_authorize_url,
                                  test_data)
        else:
            api = linkedin.LinkedIn(api_key, secret_key, post_authorize_url)

        self.api = api
        self.api.REDIRECT_URL = "/uas/oauth/authenticate"
Esempio n. 7
0
def fblogin(request):
    # we store the place to redirct to in state

    graph = get_facebook_graph(request,
                               redirect_uri=settings.FACEBOOOK_REDIRECT_URI)
    action, user = connect_user(request, facebook_graph=graph)
    user.save()
    LinkedInProfile.objects.get_or_create(user=user)
    graph = get_facebook_graph(access_token=user.get_profile().access_token)
    graph_data = graph.get('/me')
    t = loader.get_template("profile.html")
    liApi = linkedin.LinkedIn('d4sg4uq23heb', 'CECqmTcwYr9GZod5',
                              'http://creeply.dev:8000/linkedin/login')
    result = liApi.request_token()
    if result:
        graph_data['liUrl'] = liApi.get_authorize_url()
        user.liProfile.request_token = liApi._request_token
        user.liProfile.request_token_secret = liApi._request_token_secret
        user.liProfile.save()
    graph_data[
        'img'] = 'https://graph.facebook.com/%s/picture?type=large' % user.get_profile(
        ).facebook_id
    c = Context(graph_data)
    return HttpResponse(t.render(c))
 def _test_request_token(self, gae):
     "request_token doesn't raise error"
     api = linkedin.LinkedIn(API_KEY, SECRET_KEY, RETURN_URL, gae)
     api.request_token()
Esempio n. 9
0
def tag_search(request):
    query = None
    search = False
    api = linkedin.LinkedIn(*settings.LI_LIST)
    api.requestToken()
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            if form.cleaned_data.get('tags', False):
                string_tags = [
                    tag.name for tag in form.cleaned_data.get('tags')
                ]
                tag_string = " ".join(string_tags)
                search_term = "%s %s" % (form.cleaned_data['search_term'],
                                         tag_string)
            else:
                search_term = form.cleaned_data['search_term']
            if search_term.strip(' '):
                query = SearchQuerySet().auto_query(search_term)
                search = True
            else:
                form = SearchForm()
    elif request.method == 'GET':
        form = SearchForm()
        if request.GET.get('oauth_verifier', False) and request.GET.get(
                'oauth_token', False):
            verifier = request.GET.get('oauth_verifier')
            request_token = request.GET.get('oauth_token')
            request_token_secret = cache.get(request_token)
            if not request_token_secret:
                return redirect('/contacts/')
            if api.accessToken(request_token=request_token,
                               request_token_secret=request_token_secret,
                               verifier=verifier):
                profile = api.GetProfile(fields=[
                    "first-name", "last-name", "honors", "specialties",
                    "positions", "public-profile-url", "summary", "location",
                    "phone-numbers"
                ])
                tags_list = profile.specialties.replace("(", "").replace(
                    ")", "").split(",")
                trimmed_tag_list = []
                try:
                    for tag in tags_list:
                        if not len(tag) > 50:
                            trimmed_tag_list.append(tag.strip().capitalize())
                    trimmed_tags = ",".join(set(trimmed_tag_list))[0:511]
                except:
                    trimmed_tags = ""
                #assert False, trimmed_tags
                note = "<h4>Summary</h4><p>%s</p><h4>Specialities</h4><p>%s</p>" % (
                    profile.summary, profile.specialties)
                contact_data = {
                    'given_name': profile.first_name,
                    'family_name': profile.last_name,
                    'linked_in_url': profile.public_url,
                    'note': note,
                    'tags': trimmed_tags,
                    'role': profile.positions[0].title,
                    'organization': profile.positions[0].company,
                    'address_line_1': profile.location.split(',')[0],
                    'country':
                    COUNTRY_DICT.get(profile.location.split(',')[1], ""),
                    'linked_in_approval': True,
                }
                try:
                    contact = Contact.objects.get(
                        linked_in_url=profile.public_url)
                    contact.given_name = contact_data['given_name']
                    contact.family_name = contact_data['family_name']
                    contact.linked_in_url = contact_data['linked_in_url']
                    contact.note = contact_data['note']
                    contact.tags = contact_data['tags']
                    contact.role = contact_data['role']
                    contact.organization = contact_data['organization']
                    contact.address_line_1 = contact_data['address_line_1']
                    contact.country = contact_data['country']
                    contact.linked_in_approval = contact_data[
                        'linked_in_approval']
                except ObjectDoesNotExist:
                    contact = Contact.objects.create(**contact_data)
                contact.save()
                cache.delete(request_token)
                extra_context = {'contact_url': contact.get_absolute_url()}

                return render_to_response('contactlist/closeme.html',
                                          extra_context)

        cache.set(api.request_token, api.request_token_secret, 30 * 60)
    else:
        form = SearchForm()
    extra_context = {
        'auth_url': api.getAuthorizeURL(),
        'search': search,
        'query': query,
        'form': form,
    }

    return render_to_response('search/search_embedded.html', extra_context)