示例#1
0
def send_post(request):
    if request.POST:
        user = FacebookProfile.objects.get(user_id=request.user.id)
        access_token = user.access_token

        facebook = OpenFacebook(access_token)
        # facebook.get('me') # info about me

        message = request.POST.get('post_text')
        # facebook.set('me/feed', message=message, picture='http://neutr10.com/wp-content/uploads/2016/02/python-snake.jpg') # posted message for me

        photo_urls = [
            'http://neutr10.com/wp-content/uploads/2016/02/python-snake.jpg',
            'http://neutr10.com/wp-content/uploads/2016/02/python-snake.jpg',
        ]
        for photo in photo_urls:
            print facebook.set('me/feed',
                               message=message,
                               picture=photo,
                               url='http://www.me.com',
                               link=photo,
                               caption="")

        return render(request, 'send_post.html', {'message': 'Success'})
    return render(request, 'send_post.html')
示例#2
0
def share_yap_story_on_facebook(user,facebook_access_token,yap):
	facebook = OpenFacebook(facebook_access_token)
	if user.settings.facebook_connection_flag == True:
		if user.settings.facebook_account_id != None:
			name = str(yap.title.encode('utf-8'))
			if user.settings.facebook_page_connection_flag == True:
				object_api_url = str(user.settings.facebook_page_id) + '/objects/yapster_fb:yap'
			elif user.settings.facebook_page_connection_flag == False:
				object_api_url = str(user.settings.facebook_account_id) + '/objects/yapster_fb:yap'
			url = "http://web.yapster.co/yap/" + str(yap.pk) + '/'
			b = connect_s3(bucket_name="yapsterapp")
			if yap.picture_flag == True:
				yap_picture_key = b.get_key(yap.picture_cropped_path)
				yap_picture_url = yap_picture_key.generate_url(expires_in=600)
			elif yap.picture_flag == False:
				yap_picture_key = b.get_key(user.profile.profile_picture_path)
				yap_picture_url = yap_picture_key.generate_url(expires_in=600)
			if yap.description != None:
				fb_yap = facebook.set(object_api_url, object={"url":url,"image":yap_picture_url,"title":json.dumps(name),"description":json.dumps(yap.description)})['id']
			elif yap.description == None:
				fb_yap = facebook.set(object_api_url, object={"url":url,"image":yap_picture_url,"title":json.dumps(name)})['id']
			if user.settings.facebook_page_connection_flag == True:
				story_api_url = str(user.settings.facebook_page_id) + '/yapster_fb:yapped'
			elif user.settings.facebook_page_connection_flag == False:
				story_api_url = str(user.settings.facebook_account_id) + '/yapster_fb:yapped'
			fb_share_yap = facebook.set(story_api_url,yap=fb_yap)['id']
			return fb_share_yap
		else:
			return "User has not set up a facebook_account_id."
	else:
		return "User has not set up their account with Facebook."
示例#3
0
def share_new_following_story_on_facebook(user,user_followed,facebook_access_token):
	facebook = OpenFacebook(facebook_access_token)
	if user.settings.facebook_account_id != None:
		if user.settings.facebook_page_connection_flag == True:
			story_api_url = str(user.settings.facebook_page_id) + '/yapster_fb:followed'
		elif user.settings.facebook_page_connection_flag == False:
			story_api_url = str(user.settings.facebook_account_id) + '/yapster_fb:followed'
		name = str(user_followed.first_name) + ' ' + str(user_followed.last_name) + ' (@' + str(user_followed.username.encode('utf-8') +')')
		url = "http://yapster.co"
		b = connect_s3(bucket_name="yapsterapp")
		if user_followed.profile.profile_picture_flag == True:
			user_followed_picture_key = b.get_key(user_followed.profile.profile_picture_cropped_path)
			user_followed_picture_url = user_followed_picture_key.generate_url(expires_in=600)
		elif user_followed.profile.profile_picture_flag == False:
			user_followed_picture_url = None
		if user.settings.facebook_page_connection_flag == True:
			object_api_url = str(user.settings.facebook_page_id) + '/objects/yapster_fb:user'
		elif user.settings.facebook_page_connection_flag == False:
			object_api_url = str(user.settings.facebook_account_id) + '/objects/yapster_fb:user'
		description = 'Check out what @' +  str(user.username) + ' and @' + str(user_followed.username) + ' have been yapping about and listening to!'
		user_followed_object = facebook.set(object_api_url, object={"url":url,"image":user_followed_picture_url,"title":name})['id']
		fb_share = facebook.set(story_api_url,user=user_followed_object)['id']
		return fb_share
	else:
		return "User has not set up a facebook_account_id."
示例#4
0
    def post_catch_of_the_week(self):
        fish = self.queryset.first()

        graph = OpenFacebook(self.page_token)

        img_url = '{}{}'.format(settings.BASE_URL, fish.image.url)

        url = '{}{}'.format(settings.BASE_URL,
                            reverse('fish_enlarge', args=[fish.pk]))
        message = 'Fish of the week - {} {}kg. '.format(
            fish.species.name, fish.weight)
        graph.set('me/feed', picture=img_url, link=url, message=message)
示例#5
0
文件: utils.py 项目: zniper/automag
def write_facebook_status(message, link, picture=''):
    """ Post a link and message to Facebook page or timeline """
    link = build_url(link)
    try:
        fb = OpenFacebook(settings.FACEBOOK_ACCESS_TOKEN)
        # request to scrape url first
        res = fb.set('/', id=link, scrape=True)
        if res['id']:
            fb.set('me/feed', message=message, link=link)
        else:
            raise
    except:
        logger.error('Error when posting to Facebook page')
示例#6
0
def share_yap_story_on_facebook(user, facebook_access_token, yap):
    facebook = OpenFacebook(facebook_access_token)
    if user.settings.facebook_connection_flag == True:
        if user.settings.facebook_account_id != None:
            name = str(yap.title.encode('utf-8'))
            if user.settings.facebook_page_connection_flag == True:
                object_api_url = str(
                    user.settings.facebook_page_id) + '/objects/yapster_fb:yap'
            elif user.settings.facebook_page_connection_flag == False:
                object_api_url = str(user.settings.facebook_account_id
                                     ) + '/objects/yapster_fb:yap'
            url = "http://web.yapster.co/yap/" + str(yap.pk) + '/'
            b = connect_s3(bucket_name="yapster")
            if yap.picture_flag == True:
                yap_picture_key = b.get_key(yap.picture_cropped_path)
                yap_picture_url = yap_picture_key.generate_url(expires_in=600)
            elif yap.picture_flag == False:
                yap_picture_key = b.get_key(user.profile.profile_picture_path)
                yap_picture_url = yap_picture_key.generate_url(expires_in=600)
            if yap.description != None:
                fb_yap = facebook.set(object_api_url,
                                      object={
                                          "url":
                                          url,
                                          "image":
                                          yap_picture_url,
                                          "title":
                                          json.dumps(name),
                                          "description":
                                          json.dumps(yap.description)
                                      })['id']
            elif yap.description == None:
                fb_yap = facebook.set(object_api_url,
                                      object={
                                          "url": url,
                                          "image": yap_picture_url,
                                          "title": json.dumps(name)
                                      })['id']
            if user.settings.facebook_page_connection_flag == True:
                story_api_url = str(
                    user.settings.facebook_page_id) + '/yapster_fb:yapped'
            elif user.settings.facebook_page_connection_flag == False:
                story_api_url = str(
                    user.settings.facebook_account_id) + '/yapster_fb:yapped'
            fb_share_yap = facebook.set(story_api_url, yap=fb_yap)['id']
            return fb_share_yap
        else:
            return "User has not set up a facebook_account_id."
    else:
        return "User has not set up their account with Facebook."
示例#7
0
def connected_facebook_and_yapster_post_on_facebook(user,
                                                    facebook_access_token):
    facebook = OpenFacebook(facebook_access_token)
    url = "http://yapster.co"
    name = str(user.first_name) + ' ' + str(user.last_name) + " (@" + str(
        user.username) + ") just connected Yapster to Facebook!"
    description = "Click here and download the app to listen to what " + " @" + str(
        user.username) + " has been yapping about."
    b = connect_s3(bucket_name="yapsterapp")
    fb_share_yapster_picture_key = b.get_key(
        '/yapstersocialmedia/yapster_white_y_green_background')
    fb_share_yapster_picture_url = fb_share_yapster_picture_key.generate_url(
        expires_in=600)
    if user.settings.facebook_connection_flag == True:
        if user.settings.facebook_page_connection_flag == True:
            api_url = str(user.settings.facebook_page_id) + '/feed'
        elif user.settings.facebook_page_connection_flag == False:
            api_url = str(user.settings.facebook_account_id) + '/feed'
        facebook_post = facebook.set(api_url,
                                     link=url,
                                     picture=fb_share_yapster_picture_url,
                                     name=name,
                                     description=description)['id']
        return facebook_post
    else:
        return 'User has not setup Facebook Connection'
示例#8
0
    def post_social(self):
        if settings.DEBUG:
            return

        try:
            verb = self.get_verb_past()
            object = self.get_object_singular()
            if verb == "favourited":
                action_type = "deepsouthsounds:favourite"
            if verb == "liked":
                action_type = "like"
            if verb == "followed":
                action_type = "og.follows"
            else:
                action_type = "deepsouthsounds:play"

            if False:
                social_account = SocialToken.objects.filter(
                    account__user=self.user.user,
                    account__provider='facebook')[0]
                facebook = OpenFacebook(social_account.token)
                notification_html = {object: wrap_full(self.get_object_url())}
                result = facebook.set('me/%s' % action_type, notification_html)
                print(result)
        except Exception as ex:
            print(ex)
            pass
示例#9
0
def share_yap_on_facebook(user,facebook_access_token,yap):
	facebook = OpenFacebook(facebook_access_token)
	if user.settings.facebook_connection_flag == True:
		if user.settings.facebook_account_id != None:
			name = str(yap.user.first_name) + ' ' + str(yap.user.last_name) + " (@" + str(user.username) + ") posted a yap on Yapster"
			if user.settings.facebook_page_connection_flag == True:
				api_url = str(user.settings.facebook_page_id) + '/feed'
			elif user.settings.facebook_page_connection_flag == False:
				api_url = str(user.settings.facebook_account_id) + '/feed'
			url = "http://web.yapster.co/yap/" + str(yap.pk)
			b = connect_s3(bucket_name="yapsterapp")
			if yap.picture_flag == True:
				yap_picture_key = b.get_key(yap.picture_cropped_path)
				yap_picture_url = yap_picture_key.generate_url(expires_in=600)
			elif yap.picture_flag == False:
				yap_picture_key = b.get_key(user.profile.profile_picture_path)
				yap_picture_url = yap_picture_key.generate_url(expires_in=600)
			if yap.description != None:
				fb_share_yap_message = "\"" + str(yap.title.encode('utf-8')) + "\" - " + str(yap.description) + " " + "\n" + str(url)
			elif yap.description == None:
				fb_share_yap_message = "\"" + str(yap.title.encode('utf-8')) + "\" " + str(url)
			fb_share_yap_description = "Listen to this yap - and other yaps from " + str(user.first_name) + " " + str(user.last_name) 
			fb_share_yap = facebook.set(api_url, link=url, picture=yap_picture_url, name=name, description=fb_share_yap_description,message=fb_share_yap_message)['id']
			return fb_share_yap
		else:
			return "User has not set up a facebook_account_id."
	else:
		return "User has not connected their account with Facebook."
示例#10
0
    def post_weekly_gallery(self):
        graph = OpenFacebook(self.page_token)

        resp = graph.set('me/albums',
                         name='Week {}'.format(timezone.now().strftime('%W')),
                         privacy={'value': 'SELF'})
        album_id = resp['id']
        # album_id = '1482194405444590'

        graph_url = '{}/photos'.format(album_id)

        for fish in self.queryset:
            img_url = '{}{}'.format(settings.BASE_URL, fish.image.url)
            url = '{}{}'.format(settings.BASE_URL,
                                reverse('fish_enlarge', args=[fish.pk]))
            resp = graph.set(graph_url, url=img_url, link=url)
示例#11
0
    def post_social(self):
        if settings.DEBUG:
            return

        try:
            verb = self.get_verb_past()
            object = self.get_object_singular()
            if verb == "favourited":
                action_type = "deepsouthsounds:favourite"
            if verb == "liked":
                action_type = "like"
            if verb == "followed":
                action_type = "og.follows"
            else:
                action_type = "deepsouthsounds:play"

            social_account = SocialToken.objects.filter(account__user=self.user.user, account__provider='facebook')[0]
            facebook = OpenFacebook(social_account.token)
            notification_html = {
                object: wrap_full(self.get_object_url())
            }
            result = facebook.set('me/%s' % action_type, notification_html)
            print result
        except Exception, ex:
            print ex.message
            pass
示例#12
0
def share_new_subscribed_story_on_facebook(user, user_followed,
                                           facebook_access_token):
    facebook = OpenFacebook(facebook_access_token)
    if user.settings.facebook_account_id != None:
        if user.settings.facebook_page_connection_flag == True:
            story_api_url = str(
                user.settings.facebook_page_id) + '/yapster_fb:followed'
        elif user.settings.facebook_page_connection_flag == False:
            story_api_url = str(
                user.settings.facebook_account_id) + '/yapster_fb:followed'
        name = str(user_followed.first_name) + ' ' + str(
            user_followed.last_name) + ' (@' + str(
                user_followed.username.encode('utf-8') + ')')
        url = "http://yapster.co"
        b = connect_s3(bucket_name="yapsterapp")
        if user_followed.profile.profile_picture_flag == True:
            user_followed_picture_key = b.get_key(
                user_followed.profile.profile_picture_cropped_path)
            user_followed_picture_url = user_followed_picture_key.generate_url(
                expires_in=600)
        elif user_followed.profile.profile_picture_flag == False:
            user_followed_picture_url = None
        if user.settings.facebook_page_connection_flag == True:
            object_api_url = str(
                user.settings.facebook_page_id) + '/objects/yapster_fb:user'
        elif user.settings.facebook_page_connection_flag == False:
            object_api_url = str(
                user.settings.facebook_account_id) + '/objects/yapster_fb:user'
        description = 'Check out what @' + str(user.username) + ' and @' + str(
            user_followed.username
        ) + ' have been yapping about and listening to!'
        user_followed_object = facebook.set(object_api_url,
                                            object={
                                                "url": url,
                                                "image":
                                                user_followed_picture_url,
                                                "title": name
                                            })['id']
        fb_share = facebook.set(story_api_url, user=user_followed_object)['id']
        return fb_share
    else:
        return "User has not set up a facebook_account_id."
示例#13
0
def save_post(request):
    """Saves the post(both published and unpublished) for a specific page.

    Receives page id, message and a publish-unpublish flag as parameters. Then finds out the page access token for the
    page and uses it to post as the page.
    """
    if request.POST.get('publish-check'):
        published = True
    else:
        published = False
    message = request.POST['post-message']
    page_id = request.POST['page_id_post']

    user_facebook = OpenFacebook(request.user.access_token)
    response = user_facebook.get('me/accounts')
    # get page access token
    for entry in response['data']:
        if entry['id'] == page_id:
            page_access_token = entry['access_token']
            break
    facebook = OpenFacebook(page_access_token)
    facebook.set('%s/feed' % (page_id), message=message, published=published)

    return redirect('page-posts', page_id)
示例#14
0
def connected_facebook_and_yapster_post_on_facebook(user,facebook_access_token):
	facebook = OpenFacebook(facebook_access_token)
	url = "http://yapster.co"
	name = str(user.first_name) + ' ' + str(user.last_name) + " (@" + str(user.username) + ") just connected Yapster to Facebook!"
	description = "Click here and download the app to listen to what " + " @" + str(user.username) + " has been yapping about."
	b = connect_s3(bucket_name="yapsterapp")
	fb_share_yapster_picture_key = b.get_key('/yapstersocialmedia/yapster_white_y_green_background')
	fb_share_yapster_picture_url = fb_share_yapster_picture_key.generate_url(expires_in=600)
	if user.settings.facebook_connection_flag == True:
		if user.settings.facebook_page_connection_flag == True:
			api_url = str(user.settings.facebook_page_id) + '/feed'
		elif user.settings.facebook_page_connection_flag == False:
			api_url = str(user.settings.facebook_account_id) + '/feed'
		facebook_post = facebook.set(api_url,link=url,picture=fb_share_yapster_picture_url,name=name,description=description)['id']
		return facebook_post
	else:
		return 'User has not setup Facebook Connection'
示例#15
0
def notify_bidders_thread(**kwargs):
    auction = kwargs['auction']
    text = ''
    if kwargs['signal'] == 'auction_started':
        text = u'The auction for a {item} has started. Hurry and go win it!.'.format(
            item=auction.item.name)
    if kwargs['signal'] == 'precap_finishing':
        text = u'The auction for a {item} is about to start. Go play for it!.'.format(
            item=auction.item.name)
    for member in auction.bidders.all():
        of = OpenFacebook(member.access_token)
        args = {
            'template': text,
            'access_token': FacebookAuthorization.get_app_access_token()
        }
        destination = '{facebook_id}/notifications'.format(
            facebook_id=member.facebook_id)
        response = of.set(destination, **args)
示例#16
0
def _PostToFB(message):
    token = getattr(settings, 'FACEBOOK_AUTHENTICATION_TOKEN', "")
    page  = str(getattr(settings, 'FACEBOOK_PAGE_ID', 123))

    user_account = OpenFacebook(token)
    accounts = user_account.get('me/accounts')
    for x in accounts['data']:
        if x['id'] == page:
            page = x
            break
    else:
        # page not found
        print "Page not found with corresponding ID"
        return

    page_graph = OpenFacebook(page['access_token'])
    result = page_graph.set('me/feed', message=message)

    print "FB post result:", result
示例#17
0
def _PostToFB(message):
    token = getattr(settings, 'FACEBOOK_AUTHENTICATION_TOKEN', "")
    page = str(getattr(settings, 'FACEBOOK_PAGE_ID', 123))

    user_account = OpenFacebook(token)
    accounts = user_account.get('me/accounts')
    for x in accounts['data']:
        if x['id'] == page:
            page = x
            break
    else:
        # page not found
        print "Page not found with corresponding ID"
        return

    page_graph = OpenFacebook(page['access_token'])
    result = page_graph.set('me/feed', message=message)

    print "FB post result:", result
示例#18
0
def share_yap_on_facebook(user, facebook_access_token, yap):
    facebook = OpenFacebook(facebook_access_token)
    if user.settings.facebook_connection_flag == True:
        if user.settings.facebook_account_id != None:
            name = str(yap.user.first_name) + ' ' + str(
                yap.user.last_name) + " (@" + str(
                    user.username) + ") posted a yap on Yapster"
            if user.settings.facebook_page_connection_flag == True:
                api_url = str(user.settings.facebook_page_id) + '/feed'
            elif user.settings.facebook_page_connection_flag == False:
                api_url = str(user.settings.facebook_account_id) + '/feed'
            url = "http://web.yapster.co/yap/" + str(yap.pk)
            b = connect_s3(bucket_name="yapster")
            if yap.picture_flag == True:
                yap_picture_key = b.get_key(yap.picture_cropped_path)
                yap_picture_url = yap_picture_key.generate_url(expires_in=600)
            elif yap.picture_flag == False:
                yap_picture_key = b.get_key(user.profile.profile_picture_path)
                yap_picture_url = yap_picture_key.generate_url(expires_in=600)
            if yap.description != None:
                fb_share_yap_message = "\"" + str(
                    yap.title.encode('utf-8')) + "\" - " + str(
                        yap.description) + " " + "\n" + str(url)
            elif yap.description == None:
                fb_share_yap_message = "\"" + str(
                    yap.title.encode('utf-8')) + "\" " + str(url)
            fb_share_yap_description = "Listen to this yap - and other yaps from " + str(
                user.first_name) + " " + str(user.last_name)
            fb_share_yap = facebook.set(api_url,
                                        link=url,
                                        picture=yap_picture_url,
                                        name=name,
                                        description=fb_share_yap_description,
                                        message=fb_share_yap_message)['id']
            return fb_share_yap
        else:
            return "User has not set up a facebook_account_id."
    else:
        return "User has not connected their account with Facebook."