Error while getting degree connection between two users - python

I am facing a problem while fetching degree connection between two LinkedIn users. I am sending a request at
https://api.linkedin.com/v1/people::(~,id=<other person's linkedin id>):(relation-to-viewer:(distance))?format=json&oauth2_access_token=<user's access token>.
Sometimes I get a correct response:
{
"_total": 2,
"values": [
{
"_key": "~",
"relationToViewer": {"distance": 0}
},
{
"_key": "id=x1XPVjdXkb",
"relationToViewer": {"distance": 2}
}
]
}
while most of the time I get an erroneous response:
{
"_total": 1,
"values": [{
"_key": "~",
"relationToViewer": {"distance": 0}
}]
}
I have gone through LinkdIn api's profile fields and I believe that I am using the api correctly. I am not sure what's wrong here. Please help.

After posting it on LinkedIn forum, I got the response
The behavior you're seeing where you only get yourself back from your
call falls in line with what I'd expect to see if the member ID you're
asking for isn't legitimate. If the member ID exists, but isn't in ~'s
network, you should get a -1 distance back, not nothing at all, as you
are seeing. However if you put in a completely invalid member ID, only
information about ~ will be returned from the call.
This was indeed the problem. The client on Android and the client on iOS had different API keys and both were using the same backend to access the degree connection. By using the same API key for both the clients resolved the issue.

Related

How to transfers files with Google Workspace Admin SDK (python)

I am trying to write a program that transfers users drive and docs files from one user to another. It looks like I can do it using this documentation Documentation.
I created the data transfer object, which looks like this:
datatransfer = {
'kind': 'admin#datatransfer#DataTransfer',
'oldOwnerUserId': 'somenumberhere',
'newOwnderUserId': 'adifferentnumberhere',
'applicationDataTransfers':[
{
'applicationId': '55656082996', #the app id for drive and docs
'applicationTransferParams': [
{
'key': 'PRIVACY_LEVEL',
'value': [
{
'PRIVATE',
'SHARED'
}
]
}
]
}
]
}
I have some code here for handling Oauth and then I bind the service with:
service = build('admin', 'datatransfer_v1', credentials=creds)
Then I attempt to call insert() with
results = service.transfers().insert(body=datatransfer).execute()
and I get back an error saying that it 'missing required field: resource'.
I tried nesting all of this inside a field called resource and I get the same message.
I tried passing in JUST a json structure that looked like this {'resource': 'test'} and I get the same message.
So I tried using the "Try this method" live tool on the documentation website,
If I pass in no arguments at all, or just pass in the old and new user, I get the same message 'missing required nested field: resource'.
If I put in 'id':'55656082996' with ANY other arguments it just says error code 500 backend error.
I tried manually adding a field named "resource" to the live tool and it says 'property 'resource' does not exist in object specification"
I finally got this to work. If anyone else is struggling with this and stumbles on this, "applicationId" is a number, not a string. Also, the error message is misleading - there is no nested field called "resource." This is what worked for me:
datatransfer = {
"newOwnerUserId": "SomeNumber",
"oldOwnerUserId": "SomeOtherNumber",
"kind": "admin#datatransfer#DataTransfer",
"applicationDataTransfers": [
{
"applicationId": 55656082996,
"applicationTransferParams": [
{
"key": "PRIVACY_LEVEL"
},
{
"value": [
"{PRIVATE, SHARED}"
]
}
]
}
]
}
service = build('admin', 'datatransfer_v1', credentials=creds)
results = service.transfers().insert(body=datatransfer).execute()
print(results)
To get the user's Id's I'm first using the Directory API to query all users who are suspended, and getting their ID from that. Then passing their ID into this to transfer their files to another user before deleting them.

Tiktok api /user/info endpoint

Edit: Since this question is getting a good amount of views, I'd like to let you all know before you waste hours of your life on the upload endpoint that it currently requires you to manually click confirm in the app. So it doesn't allow you to fully automate uploads. To anyone which this saves time, you're welcome :)
Currently trying to implement the TikTok api into one of my projects. However having a few difficulties with a specific endpoint. Not sure if its an error on my part or on Tiktoks.
Upon making the below request I am recieving an invalid request body error message. I have followed their documentation to the T so unsure why this is happening?
https://developers.tiktok.com/doc/login-kit-user-info-basic
data = {
"access_token": access_token,
"open_id": open_id,
"fields": [
"open_id",
"union_id",
"avatar_url",
"avatar_url_100",
"avatar_url_200",
"avatar_large_url",
"display_name"
]
}
user_info = requests.post("https://open-api.tiktok.com/user/info/", data=data)
print(user_info.json())
{'data': {}, 'error': {'code': 6007055, 'log_id': '', 'message': 'invalid request body'}}
Use json parameter instead of data
import requests
data = {
"access_token": access_token,
"open_id": open_id,
"fields": [
"open_id",
"union_id",
"avatar_url",
"avatar_url_100",
"avatar_url_200",
"avatar_large_url",
"display_name"
]
}
user_info = requests.post("https://open-api.tiktok.com/user/info/", json=data)
print(user_info.json())

Python web socket doesn't return suggested data from coinbase pro api

I am trying to obtain the ticker channel data via a websocket. I am getting a response with some data, however the data I am getting is not matching the what it is suppose to show.
I have tried doing what the API specifies. The API (https://docs.pro.coinbase.com/#the-ticker-channel) says to send the request as follows:
params = {
"type": "subscribe",
"channels": [{"name": "ticker", "product_ids": ["BTC-USD"]}]
}
Now this works, and I get a response, however the response I get is:
{
"type":"ticker",
"sequence":9568995003,
"product_id":"BTC-USD",
"price":"7779.00000000",
"open_24h":"7895.99000000",
"volume_24h":"19546.97986005",
"low_24h":"7467.10000000",
"high_24h":"7945.50000000",
"volume_30d":"569908.80402872",
"best_bid":"7775.66",
"best_ask":"7778.81"
}
when the api says the output should be:
{
"type": "ticker",
"trade_id": 20153558,
"sequence": 3262786978,
"time": "2017-09-02T17:05:49.250000Z",
"product_id": "BTC-USD",
"price": "4388.01000000",
"side": "buy", // Taker side
"last_size": "0.03000000",
"best_bid": "4388",
"best_ask": "4388.01"
}
As you can see, I am missing the last_size, and side. I am unsure as to what I am doing wrong.
from websocket import create_connection
import json
URL = "wss://ws-feed.pro.coinbase.com"
ws = create_connection(URL)
params = {
"type": "subscribe",
"channels": [{"name": "ticker", "product_ids": ["BTC-USD"]}]
}
def single():
ws.send(json.dumps(params))
result = ws.recv()
print(result)
single()
The expected output should include the last_size, and side tags. Any help is greatly appreciated.
I have been implementing the same code myself and I also am not getting last_size and side included in the json. My best guess is that the json object being sent is not retrieving this information, which with my understanding means you will have to go without this information. If anyone does know of a way to retrieve this information, feel free to correct me.
EDIT: I think I have discovered the issue for why last_size is not being included in some of the responses (still unsure about side though). When the json is being printed, the price isn't changing, as I realized when I ran in a continuous while loop. Only when a trade has occurred will there be a shift in price, and therefore a 'last_size' category. I will provide the params I am passing as well as the code to illustrate how I get this result.
params = {"type": "subscribe", "product_ids": ["BTC-USD"],
"channels": ["heartbeat", {"name": "ticker", "product_ids": ["BTC-USD"]}]}
while True:
ws.send(json.dumps(params))
result = ws.recv()
print(result)
time.sleep(1)
converted = json.loads(result)
You will receive a KeyError if you try to access the 'last_size' if the price hasn't changed. My advice would be to catch this error and ignore that json, as you have all the information you already need from the json returned previously.
Hope this helps in clarifying your issue, my original response is still valid for 'side' as I have not come across anyway to receive that information.

resolve ticket as fixed with python jira api

import jira
def resolve_issue(jira,issue):
jira.transition_issue(issue, '5', assignee={'name': 'pm_user'}, resolution={'id': '3'},comment={'name':"Resolved the ticket."}))
[(u'5', u'Resolve Issue'), (u'821', u'Request Info'), (u'1011', u'Rejected'), (u'1031', u' Duplicate ')]
are the available transitions. does not work to resolve an issue as fixed with python jira rest api. I have tried to list out the transitions, but I don't see 'fixed' resolution id. Any suggestions?
added error below
text: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: N/A; line: -1, column: -1] (through reference chain: com.atlassian.jira.issue.fields.rest.json.beans.CommentJsonBean["body"])
I'm not sure if this is actually causing your problem but you have to wrap your 'assignee' and 'resolution' changes in a "fields" dict. So it would have to be something like:
fields = {
"resolution:: {
"id": "3"
},
"assignee: {
"name": "pm_user"
}
}
jira.transition_issue(issue, fields=fields, comment="Resolved the ticket.")
The JIRA REST API doesn't have very good error handling for transitions and I've seen a number of different errors (usually a 500) when the request is malformed.

400 Error while trying to POST to JIRA issue

I am trying to set the 'transition' property in a JIRA issue from whatever it is, to completed(which according to the doc is 10000). According to the documentation, this error is 'If there is no transition specified.'
Also I have used ?expand=transitions.fields to verify that 10000 is for complete.
using these docs
https://docs.atlassian.com/jira/REST/latest/#api/2/issue-doTransition
https://jira.atlassian.com/plugins/servlet/restbrowser#/resource/api-2-issue-issueidorkey-transitions/POST
Here is my request
url = 'http://MYURL/rest/api/2/issue/ISSUE-ID/transitions'
payload1 = open('data3.json', 'r').read()
payload = json.loads(payload1)
textFile = requests.post(url, auth=('username', 'password'), json=payload)
The contents on my data3.json file are
{
"transition": 10000
}
edit: I also changed my JSON to this and I get a 500 error
{
"transition": {
"id": "10000"
}
}
The error I get
{"errorMessages":["Can not instantiate value of type [simple type,classcom.atlassian.jira.rest.v2.issue.TransitionBean] from JSON integral number;no single-int-arg constructor/factory method (through reference chain:com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"transition\"])"]}400
I'm pretty confident that my issue is in my json file since I have used GET in the code above this snippit multiple times, but I could be wrong.
Possible cause - https://jira.atlassian.com/browse/JRA-32132
I believe the issue I was having was a process flow one. I cannot jump right from my issue being opened, to 'completed'. However, I can go from the issue being created to 'Done'.
{
"transition": {
"name": "Done",
"id": "151"
}
}
As this does what I need, I will use it. If I find how to make ticket complete I will post back.
Also, I think the fact we customize our JIRA lead to my getting 'Completed' as a valid transition even though it wasn't.
Yes, you're right that the JSON is wrong, it's not even a valid json since the value is not a number, string, object, or array. The doc says:
The fields that can be set on transtion, in either the fields
parameter or the update parameter can be determined using the
/rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields
resource.
So you need to do a get request on /rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields to get the list of possible values and then set that in the json
{
"transition": {
"id" : "an_id_from_response"
}
}

Categories

Resources