Is it possible to tweet via rest? - rest

I would like to tweet via rest but I'm not sure what kind of OAuth I need.
https://dev.twitter.com/oauth/overview
There are plenty of OAuth types. But every time I see that user have to go to the web site and coppy pin(PIN-based OAuth) or go to the web page to sign in or click or something.
So my question is: is it possible to tweet something using only command-line application? (I dont like to use framekorks which are specially prepared for twitter like twitter4j etc)

If you just wanna post tweet from a command line then maybe https://github.com/sferik/t can help you. Regards

As documented here https://dev.twitter.com/rest/reference/post/statuses/update the endpoint to tweet requires authentication. For this you require a token tied to a specific user.
You have 2 options
1) Generate and store a token beforehand, this is the "Tokens from dev.twitter.com" option in the link you sent.
2) Ask a user to authenticate when you want to tweet for them. This is "3-legged OAuth" or "PIN-based OAuth". You can also then store this token for reuse, and switch between tokens in your own code to post as different users. But it generally relies on a user being logged into Twitter via a browser to click approve at some point before you want to tweet.
My project oksocial has support for either approach, after which you can post with
oksocial -d "status=my message to the world" https://api.twitter.com/1.1/statuses/home_timeline.json
or even specify the user token and client secrets on the command line
oksocial --token username,consumerKey,consumerSecret,token,secret -d "status=my message to the world" https://api.twitter.com/1.1/statuses/home_timeline.json

Related

How can I allow users with their own slack account/company login to their slack account in my app

Everything I have read (e.g. https://api.slack.com/docs/oauth) makes it seem as though I can only build an app that integrates with a Slack team I manage. E.g. I have to create my Slack Client ID .. etc ... and then I can oAuth users for my team.
What I want to do is allow my app's users to login to my app using their Slack login (for their Slack team I do not control or have access to.) I don't want to force my users to generate a Client ID to use my app. I want them to login the same way Google Login or Facebook Login works.
The closest thing I have found is a "login with slack" HTML button, but I'd like to do it in iOS using Swift.
Is that possible?
Sadly, that's not possible. For google or facebook, the way authentication works is that they provide you a mobile API which handles the communication between your app and their web service. So you task is simply adopt that API, make simple function call and retrieve information for user from the API. For example, the facebook button is provided by the API.
However from a look at slack site, they only have RESTful API documented. So in this case, you have to handle the passing and storing of parameters by yourself, and send HTTP request manually. You can have a look at Alamofire framework, which is the best choice for making HTTP request. Basically, you have to send needed parameter with the specific url though HTTP request to perform a log in action, and you have to parse the respond data and then see if the login is successful or not, etc
Thanks to some help from friends it looks like the answer is yes.
You must first make sure you "Distribute App"
Then set up the permissions you require and "install app" (which is a bit not "smart" since you can accidentally add conflicting permissions and get an error when trying to install).
Once that is done you will get an Auth Token and can make requests for any user to login using oAuth.
You can also trigger a sign in request like so:
https://slack.com/oauth/authorize?client_id=[client id]&scope=identity.basic
Edit: For future Googlers, Slack now also provides a specific documentation page for this type of OAuth grant/login: Sign in with Slack

Facebook get access_token by username/password

I implement some facebook related stuff and accessing graph api for that pourposes. But for implement Integration testing I need a simple strategy to get access_token. So I create test user for that. How could I get access_token only with server side involved, without including browser in the chain. Ideally I just need to exchange login/password to the token.
Correct workflow loooks like this:
According the correct answer, there is special tests users provided by facebook.
To to be able to tests system properly you need to do the following flow
Get application access token
Request application's tests user's via "GET /{app_id}/accounts/test-users"
Parse response and extract access_tokens for each user from that response.
You can't exchange the login/password for an Access Token, but you can create test users programmatically. Have a look here:
https://developers.facebook.com/docs/graph-api/reference/v2.0/test-user
https://developers.facebook.com/docs/graph-api/reference/v2.0/app/accounts/test-users
How to get an access token with the right permissions for a test User
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/permissions/
Short answer: You can´t.
Server side you can only get an App Access Token, Page Access Token or extend an existing Access Token.
So it depends on what you need to achieve, if you just want to get public stuff from a Facebook Page, even an App Access Token may be good enough. But you cannot create User Access Tokens server side.
It may be possible with real test users created via the Graph API itself though, see Tobis answer for links about that. But it is definitely not possible with username/password.

facebook graph and access token

when I do a get request to
https://graph.facebook.com/[userid]
with the access_token i get all the basic info
but when I do
https://graph.facebook.com/me
with the same token i get an error message: An active access token must be used to query information about the current user
I have tried to under stand what can cause that.
I even tried to token that comes with the signed request
I'm on classic asp, with JSON library, I want the auto to be server side if possible. the FB.api("/me" is working but it is not what i really want to achive
I am pretty sure you don´t have a user access token. Did you login the user? Of course you get the public data of every user with your first link, even without any access token. You can even put it directly in the browser and will get results. But for "/me" you have to authorize the user to your app.
See here: https://developers.facebook.com/docs/howtos/login/server-side-login/
It is the same problem as in the other thread for sure, just a different Programming language.
Remember: If the user did not accept at least the basic permissions in a dialog or redirect, he is not logged in and you will never know anything about him in the app (except for some specifics in tab apps, like language, like-status and stuff).

Can a page on a website get a facebook access token?

I'm fairly new to facebook development and I still get confused about the oAuth thing.
A client of mine asked me to show the latest posts, links and statuses of his facebook page to his website.
On the a php page on his website I'm creating a url
"https://graph.facebook.com/".$clientFacebookPage."/posts?limit=1&access_token= xxx
In order to json decode it and display the info I want, but I don't know how to get an access token. I generated an access token with the graph explorer that is tied to my name as a facebook developer but that expires in 2 hours.
There are many thing that confuse me already and I hope you can point me towards a solution
I've read the documentation but everything revolves around users getting logged on your app and you app posting. So my questions are:
Do I need to create an app to do a curl (requiring special permissions) using the http://graph.facebook/xxxx url?
If so, does the adming of the facebook page need to authorize with the app?
What do I need to do next? I can create a web page using the app id and secret. Does that mean that I can retrieve the info of the facebook page? How?
I know that the page needs an auth token to curl the http://graph.facebook/xxxx page and retrieve the data needed. Where can I generate it? Does the webpage need to generate it, or do I have (as the app developer) acquire the token and write it to my php code?
If I log out of the facebook, will the program/webpage stop functioning?
I hope I didn't confuse you.
Thank you.
The basic process for obtaining an access token for a Page is as follows:
1. Get a user access token for a User who is an admin of the Page
2. Using this User token, request graph.facebook.com/me/accounts and look for the correct Page ID in the list returned.
3. Grab the associated Page token from that ID
4. Use it to do Page stuff.
There is a newly launched Facebook docs guide which shows you how to obtain one of these access tokens in a step-by-step fashion:
https://developers.facebook.com/docs/howtos/login/login-as-page/
Hopefully that guide should help you.
I will also answer your questions in order:
Yes, you will need an app in order to generate access tokens to make API queries
Yes
This is in the guide linked above (start at the Getting Started if you need to create a way to get a User Access Token also)
Again, see the guide above
Yes, but you should follow the steps in this guide to generate a long-lived access token. Once you do that, any Page token you retrieve will last forever.

Twitter REST change "from API" to something meaningful

When using simple request to post to Twitter the messages are signed with "sent from API". Is there a way to change that to the actual name of your application? Is it another post parameter or something else?
This is covered in the Twitter API FAQ
If you would like tweets from your application to recieve a source parameter, please register an application and implement OAuth authentication. We will automatically include your application as the source for any tweets sent from your application.
If you are writing a desktop Twitter client and you want your application's name to show up instead of "From API", you have to use OAUth.
If you want to use OAuth in your desktop Twitter application, you have to go through Twitter's PIN workflow (i.e., sending the user to the Twitter website to authenticate).
The confirmation step is part of the reason Twitter is using OAuth. There's no getting around it.
There are several libraries out there that implement OAuth for Twitter so you're not reinventing the wheel.
If you want example on how to use OAuth and Twitter I have it in my blog
"If you are writing a desktop Twitter client and you want your application's name to show up instead of "From API", you have to use OAUth.
If you want to use OAuth in your desktop Twitter application, you have to go through Twitter's PIN workflow (i.e., sending the user to the Twitter website to authenticate)."
Hold on a moment, how do Twitter clients manage to put their client name in the "via" without you logging in somewhere and copying a PIN back to the application.
I just want a command line client that updates my status and prints "via MyApp". Am I missing something here?
(I might be, I've only started trying to figure this out yesterday)
In fact if the user isn't authenticated, I don't want to get them to login elsewhere and copy/paste a PIN, I want them to type their user/pass into my application. Like what happens with all the twitter clients I've seen...