i just need some help with Twitters' API
I used the sign in with twitter flow to get the tokens needed to make calls to the API, there weren't any problems with the implementation, and so far I have got both oauth_token and oauth_token_secret so I think I have what I need to use the API.
The problem is about the last method which the documentation said about verif credentials, I am supposed to use that GET method to get a json with information about the user which has just logged into twitter by my app, however, Twitter docu doesn't mention anything about what parameters I need to pass or what headers, just the url.
I used php curl to make the calls to the API, do you know what parameters I need to pass to the API to finally get the json?
Here you have the link to the API docu:
https://dev.twitter.com/rest/reference/get/account/verify_credentials
Thanks in advance.
No params, just the 'Authorization' header.
Use the "OAuth Signature Generator" on the link you included to generate a test request and confirm yourself.
You just need to properly sign the request. This provides the context including the user, since it implicitly includes details about your request, the client secret, the user token etc.
$ oksocial https://api.twitter.com/1.1/account/verify_credentials.json
{
"id": 999999,
"id_str": "999999",
"name": "Bobby Bonson",
"screen_name": "xxxx",
"location": "CA",
"description": "...",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 699,
"friends_count": 631,
"listed_count": 34,
Related
I am using the accounts.signInWithIdp endpoint as documented here to retrieve information about a user who has signed in using an identity provider (facebook, google, twitter).
When I perform a login, I expect to retrieve an idToken, which from my understanding is the token that is used to identify and verify the logged in user. However, I only receive this token when logging in with Google, not Facebook or Twitter. I'm not sure if this has anything to do with the fact that Google is a trusted provider and Facebook and Twitter are not, though I couldn't find any documentation about this.
My desired workflow is that the client makes a request to my server using the IDP credentials, and I give them back the idToken. The client can then use this idToken to make additional requests to my server, which verifies the token with Firebase on each request.
This is implemented this way because there is information specific to each user that is stored in my own database, not on Firebase. I identify the user in my database using their Firebase ID. Is my use case reasonable and if so why can I not receive an idToken for the user?
Edit:
The code I am using comes from the firebase-php library - specifically the signInWithIdpAccessToken function documented here. The request uses Guzzle client to make the request. Here is a code snippet:
$uri = uri_for('https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp');
$postBody = [
'access_token' => $action->accessToken(),
'id_token' => $action->idToken(),
'providerId' => $action->provider(),
];
if ($action->oauthTokenSecret()) {
$postBody['oauth_token_secret'] = $action->oauthTokenSecret();
}
$body = stream_for(\json_encode(\array_merge(self::$defaultBody, [
'postBody' => \http_build_query($postBody),
'returnIdpCredential' => true,
'requestUri' => $action->requestUri(),
])));
$headers = self::$defaultHeaders;
return new Request('POST', $uri, $headers, $body);
When I print the response, I get this for a request using Facebook (some values redacted):
{
"federatedId": "http:\/\/facebook.com\/...",
"providerId": "facebook.com",
"email": "...",
"emailVerified": false,
"firstName": "...",
"fullName": "...",
"lastName": "...",
"photoUrl": "...",
"localId": "...",
"displayName": "...",
"verifiedProvider": [
"google.com"
],
"needConfirmation": true,
"oauthAccessToken": "...",
"rawUserInfo": "...",
"kind": "identitytoolkit#VerifyAssertionResponse"
}
But as you can see, no idToken field is provided.
I want to create contacts with outlook in my application.Firstly, I get into this url below
https://login.live.com/oauth20_authorize.srf?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails%20wl.contacts_create&response_type=code&redirect_uri='.$redirect_uri
I hope this is an old way to get the token,so I am
https://login.microsoftonline.com/daa825ce-e4fb-40d2-b2e6-3a2f25e62b7c/oauth2/token?client_id='.$client_id.'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails%20wl.contacts_create&response_type=code&redirect_uri='.$redirect_uri
So I get this error below.
http://prntscr.com/p4mb2c
To create contacts, you should call
POST https://graph.microsoft.com/v1.0/me/contacts
Content-type: application/json
{
"givenName": "Pavel",
"surname": "Bansky",
"emailAddresses": [
{
"address": "pavelb#fabrikam.onmicrosoft.com",
"name": "Pavel Bansky"
}
],
"businessPhones": [
"+1 732 555 0102"
]
}
You can follow this document to get the access token. Remember to grant your application Contacts.ReadWrite permission.
The scope in steps2&step3 should be https://graph.microsoft.com/Contacts.ReadWrite
Update:
To use personal account, you need to set the supported account type like below
And the authorize endpoint should use common, not the specified tenant.
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id=562855f4-f3dd-40bb-b829-515ccb96ff3f
&response_type=code
&redirect_uri=http://localhost
&response_mode=fragment
&scope=https://graph.microsoft.com/Contacts.ReadWrite
&state=12345
Also the token endpoint.
https://login.microsoftonline.com/common/oauth2/v2.0/token
In a project I am provided with API endpoints from a Firebase DB.
To retrieve data I authenticate a user with email and password (https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-email-password) and then sign every API call with the token. (These users are set up in Firebase DB)
Now one of the API endpoints returns Firebase Storage objects like this:
"fileReferences": [
{
"id": "",
"name": "images\/-s0m31D\/picture.jpg",
"mediaLink": "https:\/\/www.googleapis.com\/download\/storage\/v1\/b\/BUCKET.appspot.com\/o\/images%2F-s0m31D%2Fpicture.jpg?generation=1537959346600572&alt=media",
"selfLink": "https:\/\/www.googleapis.com\/storage\/v1\/b\/BUCKET.appspot.com\/o\/images%2F-s0m31D%2Fpicture.jpg",
"updated": 1537959346,
"size": 7759448
}
],
when I try to access fileReferences.0.mediaLink, I get an auth error.
If I send my token along with the request to mediaLink I have no luck either (https://cloud.google.com/storage/docs/downloading-objects#download-object-json)
I tried to use the Google API PHP client https://github.com/googleapis/google-api-php-client, but had no idea how I setup the new Google_Client() (I already have my auth token and I expected it to work somehow)
$client = new \Google_Client();
$client->setAccessToken(['access_token' => $token]);
How can I access the media files with my existing auth token? (or do I need a different one?)
To handle the files, I would like to use https://github.com/googleapis/google-api-php-client how can I make that work? Any hint is appreciated
Edit: I got some results in debugging the JavaScript SDK
"All" the SDK does is creating the following URL Schema
printf('https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/%s', urlencode('projects/-id/logo.png'));
//http[s]://firebasestorage.googleapis.com/<api-version>/b/<bucket>/o/<object-path>
You have to sign the call to https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/projects%2F-id%2Flogo.png with your Auth Bearer token header![1]
This returns meta data like this:
{
"name": "projects/-id/logo.png",
"bucket": "bucket.appspot.com",
"generation": "1537960188874518",
"metageneration": "1",
"contentType": "image/png",
"timeCreated": "2018-09-26T11:09:48.874Z",
"updated": "2018-09-26T11:09:48.874Z",
"storageClass": "STANDARD",
"size": "40437",
"md5Hash": "MxkOU+6feyYtdEAgKbDgp5A==",
"contentEncoding": "identity",
"contentDisposition": "inline; filename*=utf-8''logo.png",
"crc32c": "o89Y9dQ==",
"etag": "CJae8pXE2N0CEAE=",
"downloadTokens": "32c339ff9-7e4a-42a2-890a-428f8f45d378"
}
To publicly share your image, add ?alt=media&token=32c339ff9-7e4a-42a2-890a-428f8f45d378
https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/projects%2F-id%2Flogo.png?alt=media&token=32c339ff9-7e4a-42a2-890a-428f8f45d378
You don't need the token, if you send the Auth Header!
I couldn't find any mention of firebase or how to deal with my authentication in https://github.com/googleapis/google-api-php-client, so I have no idea if this would have helped me. But I got down to the basics...
Hope this helps somebody and any clearification is greatly appreciated.
QUESTION for me to better understand this all:
What are mediaLink and selfLink pointing to?
[1] if the access to storage is public you don't need to sign it.
I'm trying out IBM Watson Assistant. Ultimate goal is to integrate it with my custom PHP backend, via it's Watson Assistant's cURL API Endpoints (because there's no complete PHP SDK yet).
Let me tell what I did so far:
Imported a sample Workspace from a Training Data Set.
Then I tried this, and it works fine.
Then I tried that exact same thing via cURL API, I got a response like this: (The json output format beautified)
.
{
"intents": [
{
"intent": "locate_amenity",
"confidence": 0.999901008605957
}
],
"entities": [
{
"entity": "amenity",
"location": [
7,
10
],
"value": "gas",
"confidence": 1
}
],
"input": {
"text": "i need some gas"
},
"output": {
"text": [
"Hi. It looks like a nice drive today. What would you like me to do? "
],
"nodes_visited": [
"Start And Initialize Context"
],
"log_messages": []
},
"context": {
"conversation_id": "153c18ee-1015-4b6a-ae04-789e29bf4a05",
"system": {
"dialog_stack": [
{
"dialog_node": "root"
}
],
"dialog_turn_counter": 1,
"dialog_request_counter": 1,
"_node_output_map": {
"Start And Initialize Context": [
0,
0
]
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"AConoff": "off",
"lightonoff": "off",
"musiconoff": "off",
"appl_action": "",
"heateronoff": "off",
"volumeonoff": "off",
"wipersonoff": "off",
"default_counter": 0,
"previous_cuisine": "",
"previous_restaurant_date": "",
"previous_restaurant_time": ""
}
}
Now please let me understand 2 things here.
Question (1)
At this point, I was expecting the API to return with a message:
"There are gas stations nearby. Which one would you like to drive to?"
But why it doesn't. If then, how do I achieve it?
Question (2)
How do I properly reply back with "Go to number 5." so that the API understands I'm referring to the previous Call? (aka) How to I continue the dialog flow? (Note: I tried sending back with the previous "contexts", "entities", "intents", but it is somehow still recognised as a new message.)
Please share me an example of cURL call to follow up the previous message.
Since there's no complete PHP SDK yet, it is very hard for me to understand just by the cURL API calls. API Documentation does not explain to that details too. Please help.
Thank you all.
The message API for Watson Assistant is stateless. Everything that is needed to process a request is submitted as parameters. This includes the message itself, but also the context. The context holds the state about where in the dialog tree the conversation is. It could also hold information that is transferred from WA to the app, e.g., to process a client-side action. Or from the app to WA, e.g., with a record from a database.
Coming to your request:
Your dialog probably sends out that reponse when a new conversation is started. I see it is the same as in the "Try it out".
You would need to send a "Hi" or empty message first, wait for the reponse from WA, then send your "I need gas" together with the context data you received from WA. WHen you look into the details, you see the dialog stack, turn counter and more. The conversation ID is the identifier for that current chat.
With the above, WA's next response should be exactly like in the "Try it out" because you went down in the dialog tree.
I'm currently writing a PHP application.
I noticed something strange when it wasn't returning the persons birthday.
To cut a long story short, when i manually query the graph api, it gives me the full result set (birthday, email etc. included). However, when I run it in my app, it comes back as if i've not sent the access token.
When I manually visit the address it produces:
{
"id": "507665705",
"name": "Ally Dewar",
"first_name": "Ally",
"last_name": "Dewar",
"link": "https://www.facebook.com/alastair.dewar",
"username": "alastair.dewar",
"birthday": "06/22/1990",
"location": {
"id": "113744028635772",
"name": "Greenock"
},
"gender": "male",
"email": "alastair\u0040alastairdewar.co.uk",
"timezone": 1,
"locale": "en_GB",
"verified": true,
"updated_time": "2012-03-11T15:56:19+0000"
}
However, when my application makes the same request (exact same URL), it comes back with
{"id":"507665705","name":"Ally Dewar","first_name":"Ally","last_name":"Dewar","link":"http:\/\/www.facebook.com\/alastair.dewar","username":"alastair.dewar","gender":"male","email":"alastair\u0040alastairdewar.co.uk","locale":"en_GB"}
My instinct says it could be a setting within the facebook app, as it wasn't a problem beforehand.
EDIT: https://developers.facebook.com/bugs/412680422092698?browse=search_4f854dc037a2a5d12811839
Thanks for any advice.
Make sure you ask for all the permissions that you need and also remove the app and start again. Make sure you ddon't cache any of the responses as well.
How do you query the API? Graph Explorer or just manually open the link (graph.facebook.com/USER_ID) and pass the auth token generated by the app? Testing with the Graph Explorer won't help you with your problem as permissions etc are different.
As mentioned by Nobita, code helps. This is as much as I can advise considering the amount of data you're giving us.