i looking make api call grab post data of protected wp blog. having trouble translating wp authentication procedure php r, think in part because don't understand process.
my understanding of oauth token receipt procedure comes this page:
- send user authorization endpoint prompts login:
https://public-api.wordpress.com/oauth2/authorize?client_id=your_client_id&redirect_uri=your_url&response_type=code&blog=1234
- then make
post
request @ api code in above redirect url incorporated:
$curl = curl_init('https://public-api.wordpress.com/oauth2/token'); curl_setopt( $curl, curlopt_post, true ); curl_setopt( $curl, curlopt_postfields, array( 'client_id' => your_client_id, 'redirect_uri' => your_redirect_url, 'client_secret' => your_client_secret_key, 'code' => $_get['code'], // code previous request 'grant_type' => 'authorization_code' ) ); curl_setopt( $curl, curlopt_returntransfer, 1); $auth = curl_exec( $curl ); $secret = json_decode($auth); $access_key = $secret->access_token;
which returns:
{ "access_token": "your_api_token", "blog_id": "blog id", "blog_url": "blog url", "token_type": "bearer" }
but have no idea start in r. apologize not reproducible problem. tried use code here, can't quite figure out went wrong:
app_name <- 'myapp' client_id <- 'your_client_id' redirect_uri <- 'your_redirect_url' client_secret <- 'your_client_secret_key' resource_uri <- #idk oauth_endpoint(authorize = "https://public-api.wordpress.com/oauth2/authorize?client_id=your_client_id&redirect_uri=your_url&response_type=code&blog=1234", access = "https://public-api.wordpress.com/oauth2/token") wordpress_endpoint <- oauth_endpoints('wordpress') # create app instance. myapp <- oauth_app(key = 'your_client_id', secret = 'your_client_secret_key') mytoken <- oauth2.0_token(wordpress_endpoint, myapp, user_params = list(resource = resource_uri), use_oob = false)
there built in endpoints apis... don't have urls yourself. don't thing wordpress 1 of them, that's creating oauth_endpoint
call. might work... don't have wordpress account test it...
wordpress <- oauth_endpoint(authorize = "https://public-api.wordpress.com/oauth2/authorize?client_id=your_client_id&redirect_uri=your_url&response_type=token&blog=1234", access = "https://public-api.wordpress.com/oauth2/token") myapp <- oauth_app(key = 'your_client_id', secret = 'your_client_secret_key') mytoken <- oauth2.0_token(wordpress, myapp)
Comments
Post a Comment