I need to access my podio app using access_token instead of being using username and password. The code i tried using username and password and its working finr for me. I'm using
ResourceFactory resourceFactory = new ResourceFactory(
new OAuthClientCredentials("usedClientId","usedClientSecret"),
new OAuthUsernameCredentials("abc@ggtd.com","Test123"));
APIFactory apiFactory = new APIFactory(resourceFactory);
ItemAPI itemAPI = apiFactory.getAPI(ItemAPI.class);
But i need to use accesstoken so that i may not be dependent on username and password for accessing app. For this i tried using
URL url = new URL("https://podio.com/oauth/token?granttype=app&appid=88069&apptoken=6a83845c6656ff4678a5eec668a10aa3e7&clientid=usedClientId-79unji&redirecturi=https://podio.com/abcd/workappname/apps/usedClient&client_secret=jIfs6qWsQJJ99eDDds1RMhmbKywAhsMtTYLFW8GVeFmmeAiCYOOdzDyc3yqdHBT");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
and i'm getting the response in the form of JSON like
{
accesstoken: "ae566736ffdb414ab23320c9d169d8a"
tokentype: "bearer"
ref: {
type: "app"
id: 88069
}-
expiresin: 98800
refreshtoken: "96bbfb0dd9e74ac6ad456f44896c4d3e"
}
which is 200 Response. I took help of using https://github.com/podio/podio-java/tree/master/src/main/java/com/podio but no use. Also refer https://developers.podio.com/authentication where also no help . Now , How can i use this access_token in my java code?
First of all, NEVER post application id and secrets on such a websites.
You can use any JSON-parsing library to get this information, for example, the simplest example with GSON would be following:
public class AuthInfo {
private String accesstoken, tokentype, ...
public String getAccessToken() {
return accesstoken;
}
}
// ...
Gson gson = new Gson();
String accessToken = gson.fromJson(response, AuthInfo.class).getAccessToken();
Have you tried OAuthRefreshTokenCredentials ?
You should be able to use OAuthRefreshTokenCredentials which implements OAuthUserCredentials and let you use the refresh_token instead of the user_name / password (required in OAuthUsernameCredentials).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.