SRC link changed when trying to integrate paypal button on django website - python

I'm trying to add the paypal button to my django shopping site.
I have used the code from the SDK and replaced the id:
My code:
Client ID being: AWeSepzeHNW8BHE8rWPVm6CTuAGKz7SS1WzpbqEOZvQw-s_6qwFg6lxCO9MSXPpcVheUBWRgNuW6yKol
However i am receiving a 400 error.
Also viewing the page source shows the src has changed:
If you follow this link you get the following message:
throw new Error("SDK Validation error: 'Invalid query value for client-id: AabgYuFGxyzy3AbeWLPa-EtEGGreyL9bDDbWOxH4zFbPbgNc7y5yMpNO7B2NMRxCvT7-Ysou8ZXDNycT¤cy=USD'" );
/* Original Error:
Invalid query value for client-id: AabgYuFGxyzy3AbeWLPa-EtEGGreyL9bDDbWOxH4zFbPbgNc7y5yMpNO7B2NMRxCvT7-Ysou8ZXDNycT¤cy=USD (debug id: f3776258140b9)
*/
Anyone know why the src has been changed from the source to when its rendered by django?
I have followed the original src link from paypal and this, however when the page renders the link is altered.

I found out what the problem was. I had to replace the & with & in the
<script src="https://www.paypal.com/sdk/js?client-id=test&currency=USD"></script>
tag.

Related

Python Dash Plotly: dcc.Upload gives error POST 500 after deployment

I used dcc.upload() to handle the file upload. The file can be uploaded and read locally on the localhost.
But after the deployment, I received POST 500 internal server error. And the message received is:
{message: "Callback error updating output-data-upload.children", html: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final/…ded or there is an error in the application.</p>\n"}
The code related to this error message has been attached below as a screenshot, where output-data-upload is the id of a html.Div() component.
And the upload-data is the id of the dcc.Upload() component.
In the parse_contents(), I'm trying to filter for xls or xlsx files only. in the update_output(), I'm trying to display the name of the uploaded file.
I've looked up the 500 error code and have tried to change some permission settings but nothing really worked out.\
I really appreciate the help!
code related

path('<username>') causing all urls to map to incorrect view

I have a Django app called chat and the root urls.py looks like this
path('messages/', include('chat.urls')),
However the url below, in the chat app urls.py is causing problems
re_path(r"^(?P<username>[\w.#+-]+)", login_required(chat_views.ThreadView.as_view()), name='thread'),
What is happening is that instead of throwing a 404 does not exist
error when I go to a made up url such as
localhost/messages/blahblah/02
It instead throws
NOT NULL constraint failed: chat_thread.second_id
Because it is assuming blahblah/02 is a username and is mapping it to the ThreadView which fails to get the thread object from 2 users.
So essentially, any other url pattern I try to create in the chat app doesn't route properly. (Example I tried creating a NotificationListView but couldn't access it due to routing messages/notifications to ThreadView)
How can I stop this from happening?

Publish pictures on Facebook page events using python

I'm trying to publish pictures on Facebook events under Facebook pages I own as that owning page using python. I am attempting to do so as the admin of an app.
The best understanding I have of the process (obviously not good enough) is that it is a two step process: 1) get page_token for target page using user_token (have a long-lived one) 2) use page_token to publish content.
Something like this:
def getFbGraph(accessToken=user_token):
return facebook.GraphAPI(access_token=accessToken)
page_token = getFbGraph().get_object(pageID, fields=['access_token'])
getFbGraph(page_token).put_object(parent_object=eventID, connection_name='photos', message='This is my caption', url=imgUrl)
That gets me the following error message:
facebook.GraphAPIError: Invalid OAuth access token
If instead I try to put the photo as a user (i.e. without the pageToken) I get the following message:
facebook.GraphAPIError: (#200) Requires extended permission: publish_actions
Is there no way for the admin of a page and an app to programmatically post allowed content? I don't need other FB users to be doing that (hence need to go through the publish_actions permissions) and I own all the pages I'm posting to.
Many thanks in advance for your comments.

Best way to gather g+ avatar/name for appengine app

editied original question:
Im trying to make a google appengine app which uses the g+ avatar and human name...
...
So it seems that i need the google-api-python-client library in my app.
...
to enable access to the profile scope so i can look up 'me' and grab the users name and avatar and chuck them in a couple of properties in my user objects (with a button to reload the values again or something).
So has anyone does this? Or has a working example (or even a pointer to which of the ways to authorise my app for scope=[profile])?
Discoveries:
I dont need the google-api-python-client library for this. The simple approach was to do the g+ access in pure js on the client and then lookup and push the results to my appengine app. It isnt as secure as doing via the backend, but it is only for displayname and icon (which can be set manually anyway).
I did need to make some other tweaks to make it work though...
following this workflow:
https://developers.google.com/+/web/signin/javascript-flow
Important things to note:
step1 should also state that you MUST fill out "APIs & auth" -> "Consent screen" field "PRODUCT NAME" and "EMAIL ADDRESS" or you get weird errors
You (might) have to do this before you generate the credential (or delete and recreate it)
(credit to answer: Error: invalid_client no application name)
set meta google-signin-scope to "profile" (or maybe "email")
remove the meta header for google-signin-requestvisibleactions (otherwise i got a frame sameorigin error)
obviously the button line from step4 needs to go after the body tag in your document
skip step2, the code from step2 is also included in step4
also on the workflow page, the 'working example' button on that page does not work (dont try it)
Once i did that I could put the following in the successful callback code and do a lookup:
gapi.client.load('plus','v1', function(){
var request = gapi.client.plus.people.get({ 'userId': 'me' });
request.execute(function(resp) {
console.log('Retrieved profile for:' + resp.displayName);
console.log(resp);
console.log(resp.result);
console.log(resp.result.displayName);
console.log(resp.result.image);
});
});
you can see here full example on how to use client library
https://code.google.com/p/google-api-python-client/source/browse/samples/plus/plus.py
i see a snippet of the code stating
try:
person = service.people().get(userId='me').execute()
print 'Got your ID: %s' % person['displayName']
https://developers.google.com/+/api/latest/people#resource
so basically person['image']['url'] will be your path to user's avatar.
full folder: https://code.google.com/p/google-api-python-client/source/browse/samples/plus/

Posting to Facebook App page wall as the App Page in python

I am trying make a post on my apps page wall as if it is coming from the app page (not another user) After researching I seem to find no solution that actually works!
I have tried to follow the documentation here:
I then get my 'access_token_page' by getting it from:
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=CLIENT_SECRET&grant_type=client_credentials
Then using the facebook python api I try:
graph1 = facebook.GraphAPI(access_token_page)
graph1.put_wall_post(fbmessage, attachment, profile_id=APP_PAGE_ID)
However this just returns the following facebook error:
*** GraphAPIError: (#200) The user hasn't authorized the application to perform this action
Any ideas on what I am missing? Remember, I am looking to have the App Page make a post to itself, not have a post be generated from another username.
Thank you!
What you had done is using App Access Token to publish to page.
You should using Page Access Token to post on page admin behalf instead. User Access Token is works too but it's a bug as reported at https://developers.facebook.com/bugs/647340981958249, so it's not recommended to use User Access Token by this time of writing.
As documented at https://developers.facebook.com/docs/reference/api/page/#page_access_tokens:
Page Access Tokens
To perform the following operations as a Page, and not the current
user, you must use the Page's access token, not the user access token
commonly used for reading Graph API objects. This access token can be
retrieved by issuing an HTTP GET to /USER_ID/accounts with the
manage_pages permission.
More info about different type of access token please visit https://developers.facebook.com/docs/facebook-login/access-tokens/
Try Django Facebook:
https://github.com/tschellenbach/Django-facebook
This will deal with many of your API problems.
You need the page access token, see here:
https://developers.facebook.com/docs/facebook-login/access-tokens/
Ask for manage_pages as an extra permission
After getting that setup, simply do:
user_graph = OpenFacebook(user_access_token)
response = user_graph.get('me/accounts')
# turn the response to a dict, and be sure to get the page you want
page_access_token = response['data'][0]['access_token']
graph = OpenFacebook(page_access_token)
graph.set('me/feed', message='helloworld')
You can find more docs here:
http://django-facebook.readthedocs.org/en/latest/open_facebook/api.html

Categories