1
実際に私はアンドロイドアプリでfacebook sdkを使用しているユーザーではなく、グラフリクエストから取得するページ「AccessToken」です。私は他のグラフ要求でそれを使用することはできません。それはStringがAccessTokenに変換できないと言う。facebookアクセストークンをグラフapiの文字列として使用する方法
ここに私のコードです。
package com.mak.masimmak.pageshare;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.facebook.AccessToken;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.HttpMethod;
import org.json.JSONException;
import org.json.JSONObject;
public class sharePage extends AppCompatActivity {
Button shareButton;
public String PageId;
String PageAccessToken;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share_page);
shareButton = (Button) findViewById(R.id.shareButton);
shareButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
if(getIntent().getExtras() != null) {
Bundle extras = getIntent().getExtras();
PageId = extras.getString("PageId");
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/"+PageId+"?fields=access_token",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
try {
JSONObject data = response.getJSONObject();
PageAccessToken = data.getString("access_token");
PostOnPage();
} catch (JSONException e) {
Toast.makeText(sharePage.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
}
).executeAsync();
}
}
});
}
public void PostOnPage(){
Bundle params = new Bundle();
params.putString("message", "This is a test message");
/* make the API call */
new GraphRequest(
/* Problem is here the PageAccessToken is in String How to use this string token here? */
(AccessToken) PageAccessToken,
"/"+PageId+"/feed",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
}
}
私はグーグルで問題を検索し、私は..
public AccessToken(String accessToken, String applicationId, String userId, Collection permissions, Collection declinedPermissions, AccessTokenSource accessTokenSource, Date expirationTime, Date lastRefreshTime)
何かを見つけたが、私はこれを使用するか、私のコードでこれを実装する方法がわかりません。