无法获取用户

时间:2016-11-02 13:44:24

标签: api twitter tweets

当我打印$ tweets时,它给出了像

这样的错误的数组
  

[body] => {“errors”:[{“message”:“抱歉,该页面不存在”,“代码”:34}]}

private function fetch_tweets($tweet_count,$username){
    $tweets = wp_remote_get("http://twitter.com/statuses/user_timeline/$username.json");

    print_r($tweets);

    if(isset($tweet->error) ) return false;

    foreach($tweets as $tweet){
        if($tweet_count-- === 0) break;
        echo $tweet->text;
    }
}

1 个答案:

答案 0 :(得分:1)

正如ardavey所提到的,你需要阅读http://bestinthink.com/wg/buy-p1.html

  

示例请求

     

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.karanvir.search.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/i"> <AutoCompleteTextView android:id="@+id/autoCompleteTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginTop="63dp" android:background="@android:color/background_light" android:hint="Search here" android:textColor="@android:color/background_dark" /> <Button android:id="@+id/button" android:layout_width="170dp" android:layout_height="170dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@drawable/s" android:onClick="jump" android:text="Go" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="100dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:background="@drawable/t" android:textColor="@android:color/holo_green_light" android:textSize="10sp" /> <ProgressBar android:id="@+id/progressBar2" android:indeterminateTint="@android:color/holo_blue_bright" android:layout_width="230dp" android:layout_height="230dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout> </android.support.design.widget.CoordinatorLayout>

所以,对于你的PHP:

package com.karanvir.search;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    Random rn;

    AutoCompleteTextView searchBar;
    public static String urlGlobal;
    TextView con;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        searchBar=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
        Button button=(Button) findViewById(R.id.button);
        con=(TextView) findViewById(R.id.textView);

         rn= new Random();








    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings4) {
            Intent intentGoogle= new Intent(getApplicationContext(),Main2Activity.class);
            startActivity(intentGoogle);



            return true;
        } else if(id ==R.id.action_settings2){
            Intent intentGoogle= new Intent(getApplicationContext(),Yahoo.class);
            startActivity(intentGoogle);


            return true;

        }else if (id==R.id.action_settings3){
            Intent intentGoogle= new Intent(getApplicationContext(),MainActivity.class);
            startActivity(intentGoogle);


            return true;

        }else if(id==R.id.action_settings1){
            new AlertDialog.Builder(this)
                    .setIcon(android.R.drawable.ic_dialog_info)
                    .setTitle("About")
                    .setMessage("This app interchanges between different search engines, to help guess what your looking for. We dont not acess your location, also we do not save any information. Right now we are working on a way to make the app completely private in congnito.Email us if you want to help with this project also. Please email Dhillonapps93@gmail.com for help/inquries. We run this app with no ads, we also accept donations at runescapegold1291@hotmail.com. Yes I used to play runescape lol. Thanks for reading and enjoy");
                    return true;

        }

        return super.onOptionsItemSelected(item);
    }


    public void jump(View view){
        //intnet changing target of our code
urlGlobal=searchBar.getText().toString();
        Log.i("stuff",urlGlobal);




        int pageJump = rn.nextInt(3)+1;
        if (pageJump==1){
            //google
            Intent intentGoogle= new Intent(getApplicationContext(),Main2Activity.class);
            startActivity(intentGoogle);
        } else if (pageJump==2){
            //YAHOO
            Intent intentGoogle= new Intent(getApplicationContext(),Yahoo.class);
            startActivity(intentGoogle);

        } else if(pageJump==3){
            //GOOGLE
            Intent intentGoogle= new Intent(getApplicationContext(),Main2Activity.class);
            startActivity(intentGoogle);

        }


    }


}

此外,并非您需要验证您的请求:

  

请注意,API要求对请求进行身份验证(请参阅身份验证和授权文档......

请参阅API Documentation开始使用。