2013-05-22 34 views
1

我正在構建一個instagram應用程序,我將在其中顯示用戶將要編寫的目標用戶的照片。是否有可能從我的應用程序中跟隨該人?我們如何從我們的應用程序跟隨一個人的instagram?

我用這段代碼在instagram中喜歡圖片。

try { 
    URL url = new URL(API_URL + "/media/" + instapostid + "/likes?access_token=" + accessToken); 
    Log.d(TAG, "Opening URL " + url.toString()); 
    HttpURLConnection urlConnection; 
    urlConnection = (HttpURLConnection) url.openConnection(); 

    urlConnection.setRequestMethod("GET"); 
    urlConnection.setDoInput(true); 
    urlConnection.setDoOutput(true); 
    urlConnection.connect(); 

其中API_URL是

private static final String API_URL = "https://api.instagram.com/v1"; 

回答

3

你在Instagram的API文檔看?

這似乎是你在找什麼:

https://api.instagram.com/v1/users/[user-id]/relationship?access_token=[ACCESS-TOKEN] 

修改當前用戶與目標用戶之間的關係。

PARAMETERS: 
ACCESS_TOKEN A valid access token. 
ACTION One of: follow/unfollow/block/unblock/approve/deny. 

所以,如果你登錄你應該能夠在POST發送到這個網址給目標用戶ID的訪問令牌和一個動作參數「跟隨」

See this page for more

+0

但我無法給行動=跟隨,我應該如何把它? – Saad

+0

作爲您的發佈請求的參數。 – FoamyGuy

+0

即時通訊新的android編程,所以你可以告訴我如何發送參數? – Saad

2

試試這個:

TextView txtFollow = (TextView) findViewById(R.id.txtFollow); 
txtFollow.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 
        Uri uri = Uri.parse("http://instagram.com/_u/URL"); 
        Intent likeIng = new Intent(Intent.ACTION_VIEW, uri); 

        likeIng.setPackage("com.instagram.android"); 

        try { 
         startActivity(likeIng); 
        } catch (ActivityNotFoundException e) { 
         startActivity(new Intent(Intent.ACTION_VIEW, 
           Uri.parse("http://instagram.com/URL"))); 
        } 

       } 
}); 
+0

這只是一個意圖,問題是如何使用Instagram API – hadi

相關問題