python slack API missing scope error despite appropriate scope for the bot token - python-3.x

I am trying to create a Slack API + Python web hook. I have setup the app and the bot tokens with the proper scope needed to create DM's with users and post messages. I am trying a sample script that will open channel.
import sys
import logging
logging.basicConfig(level=logging.DEBUG)
from slack_sdk import WebClient
slack_token = "xoxb-<random_value>"
client = WebClient(token=slack_token)
api_response = client.conversations_open(channel="user1")
I get an error response from the API:
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/conversations.open)
The server responded with: {'ok': False, 'error': 'missing_scope', 'needed': 'channels:write,groups:write,mpim:write,im:write', 'provided': 'incoming-webhook'}
Can someone please help ? For some reason, it identifies only the incoming-webhook. First time doing this. Any help appreciated

Related

API.put_photo is deprecated. Is there a new method for publishing photos or Figures on Facebook using Python API?

I am using facebook API (version 3.1.) to publish automatically on my Facebook feed using a python script (shown below), which was working fine until recently. I found that facebook deprecated the put_photo function from the new api version (8.0), but can't find how to call the new function or new method to publish photos automatically from the python script. So, Is there a new way to do this? What am I missing?
Thanks a lot for the help!
import facebook
import sys,os
import json
import numpy as np
def facebook_post_sentido(figure_name):
def get_cfg():
cfg = {
"page_id" : "my_id"
"access_token" : "my_token"
}
return cfg
def gen_api(cfg):
API = facebook.GraphAPI(cfg['access_token'])
print("generating api connection")
return API
cfg = get_cfg()
API = gen_api(cfg)
photo_id = API.put_photo(image=open(figure_name, 'rb'), )
# API.put_object(parent_object=cfg["page_id"], connection_name="feed",
# message="SISMO SENTIDO RELOCALIZADO",
# attached_media=json.dumps([{'media_fbid': str(photo_id.get('id', ''))}]))
facebook_post_sentido(figure_name="myfigure")
When I run the code I get the following error:
facebook.GraphAPIError: (#200) This endpoint is deprecated since the required permission publish_actions is deprecated
There is no way to post a photo onto user profiles via API any more.
This has been completely removed, same as making normal posts via API. With the exception of live videos, you can not publish anything any more onto user profiles via API.
Apps wanting to provide sharing functionality to end users, can use one of the dialogs provided. (But even those don’t allow a photo upload, you can only share links.)

Youtube oauth2 authorization returns redirect_uri_mismatch

I am trying to access the Youtube API via python so that I can insert videos into a playlist. To do so I have to use oauth2 to authorize myself. I have looked up many guides and videos and followed their instructions step by step but I always get the same result, saying Error 400: redirect_uri_mismatch
The code that I am using is
from google_auth_oauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.from_client_secrets_file("client_secrets.json", scopes=['https://www.googleapis.com/auth/youtube.force-ssl'])
flow.run_local_server(port=8080, prompt='consent')
credentials = flow.credentials
print(credentials.to_json())
I have also tried
from google_auth_oauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.from_client_secrets_file("client_secrets.json", scopes=['https://www.googleapis.com/auth/youtube.force-ssl'])
flow.run_console()
credentials = flow.credentials
print(credentials.to_json())
I understand that this occurs when there is a mismatch between the redirect_uri on the request side and what is listed in the console. But I have triple checked that on https://console.developers.google.com/ I have the redirect URI to be http://localhost.com:8080 and have checked to make sure that my client_secrets.json file reflects the same. I have set my JavaScript origins to also be http://localhost.com:8080. I have set my oauth clientID to be a web application as I am running this in pycharm. However, whenever I run my code I get the same error saying The redirect URI in the request, http://localhost:8080/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}
I have looked at the other questions on stackOverflow and have tried the solutions that were suggested but none of them have worked. I have no idea why I cannot get authorization and desperately need help

people.connections.list not returning profile details and contacts in Python using Google-People API

I've connected with Google's People-API in the google console using oauth2.0 by creating credentials. And while I'm trying to get user's profile details and contact details by using this API in google, I'm not able to get that. Below is the sample code for the authentication and getting data.
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run_flow
# Set up a Flow object to be used if we need to authenticate. This
# sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with
# the information it needs to authenticate. Note that it is called
# the Web Server Flow, but it can also handle the flow for
# installed applications.
#
# Go to the Google API Console, open your application's
# credentials page, and copy the client ID and client secret.
# Then paste them into the following code.
FLOW = OAuth2WebServerFlow(
client_id='xxxxxxxxx-xxxxxxxxxxxxxxxxx',
client_secret='xxxxxxxxxxxxxxxxxxxx',
scope='https://www.googleapis.com/auth/contacts.readonly',
user_agent='myapp/2.0',
redirect_uri='http://localhost')
# If the Credentials don't exist or are invalid, run through the
# installed application flow. The Storage object will ensure that,
# if successful, the good Credentials will get written back to a
# file.
storage = Storage('info.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = run_flow(FLOW, storage)
# Create an httplib2.Http object to handle our HTTP requests and
# authorize it with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)
# Build a service object for interacting with the API. To get an API key for
# your application, visit the Google API Console
# and look at your application's credentials page.
people_service = build(serviceName='people', version='v1', http=http)
connections = people_service.people().connections().list('people/me', pageSize=100, personFields='names,emailAddresses').execute()
profile = people_service.people().get('people/me', pageSize=100, personFields='names,emailAddresses').execute()
After running the above code. I got the following error.
Traceback (most recent call last):
File "people_api_auth.py", line 43, in <module>
connections = people_service.people().connections().list('people/me', pageSize=100, personFields='names,emailAddresses').execute()
TypeError: method() takes 1 positional argument but 2 were given
Can anyone explain why I'm getting this error.
Any help would be greatly appreciated.
Thank you!!!
Take a look at the sample at https://developers.google.com/people/quickstart/python
Looks like they use list(resourceName='people/me' instead of list('people/me'

Is it possible to use the Azure URL Ping Test to test whether a Direct Line Bot is alive?

I have a Web App Bot running on Azure.
It's using the Microsoft Bot Framework Direct Line API 3.0.
I want to use the URL Ping Test type instead of the Multi-Stage Web Test for the Availability Test of the Bot because I do not have the Visual Studio 2017 Enterprise edition.
In the Bot's message controller, this is how I handle the response for Pings.
I am able to get expected response in the Bot emulator when running the Bot in localhost.
else if (message.Type == ActivityTypes.Ping)
{
ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl));
var reply = message.CreateReply();
reply.Text = "{Some message}";
await client.Conversations.ReplyToActivityAsync(reply);
}
However, when I connect to the Bot in Azure, I am getting HTTP error 500.
I'm not sure what is the root cause and wonder whether it is due to the URL Ping Test does not know the Direct Line secret.
Appreciate your kind help on this.
Thanks very much.
If you check the “Send an activity to the bot” in Direct Line API 3.0 documentation, you can find:
To send an activity to the bot, the client must create an Activity object to define the activity and then issue a POST request, specifying the Activity object in the body of the request.
URL ping test would sned a GET request to the URL that you specified, it would not hit/trigger the code that you defined for Ping activity in your MessagesController.
If you’d like to detect whether your bot is alive by sending a Ping activity, you could make a request like below from your client.
Request:
POST https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
Authorization: Bearer {directline_secret}
Content-Type: application/json
Body:
{
"type": "ping",
"from": {
"id": "user1"
}
}

Oauth2 Client ID Matching with Wrong Project

I have two separate Google App Engine projects (let's call them projects A and B) that I'm using Oauth2 to validate users for. For each project, I generated its own Oauth 2.0 Client ID.
So for project B, attempting to verify my Oauth2 token yields a value error. From what I can tell, for some reason it's expecting the ClientID from project A. Using project A's Client ID actually makes everything work as expected, which seems weird.
I'm using Python3.5 for this project and trying to use to deploy a webpage using Flask, if that helps anything.
Error Code: (keys redacted)
Token has wrong audience <Client ID A>, expected <Client ID B>
Code for verifying token:
from google.oauth2 import id_token
from google.auth.transport import requests as goog_requests
from flask import Flask, render_template, request
...
# Verify and get info for the user's ID token.
# This is where the error gets thrown
idinfo = id_token.verify_oauth2_token(
request.headers.get('X-id-token'),
goog_requests.Request(),
CLIENT_ID
)
Additional info - as I'd expect with that error code, the UI for loging in indicates that I'm trying to login to project A as well. I'm also wondering if this has anything to do with my google sdk cli configuration. I tried resetting my default project to project B but that didn't change anything.
Any help is greatly appreciated!
I'm dumb. I didn't change the sign-in object(?) in my HTML to match the new Client ID. I had to change
<meta name="google-signin-client-id" content="CLIENT_ID">
to the new client ID.

Resources