Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

collections - Meteor using a local connection results in error: insert failed: 404 -- Method not found

I've got a meteor collection on the client side

Friends = new Meteor.Collection("Friends");
Meteor.subscribe("Friends");

I have a user authenticate with facebook and I want to grab a list of their friends:

FB.api("/me/friends?    auth_token="+response.authResponse.accessToken,
    function(response){
        for (i = 0; i<response.data.length;i++){
            Friends.insert(response.data[i]);
    }
);

I have a function to get that list:

Template.Friends.all_friends = function(){
    return Friends.find();
} 

I have a template that would like to display all the friends on the screen:

<template name="Friends">
    {{#each all_friends}}
    <div id="{{id}}" class="friend">
        <img src="http://graph.facebook.com/{{id}}/picture" />
        {{name}}
    </div>
    {{/each}}
</template>

What appears to be happening on the page is that all the friends DO flash up on the screen for a split second then immediately the screen flashes back to blank.

In the javascript console the message appears once per friend I have (yes, it is more than zero, thanks for asking)

insert failed: 404 -- Method not found

So! What have I missed? Anyone?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need that Collection declaration on both the client and the server.

// common code, do not put under /client or inside Meteor.is_client test
Friends = new Meteor.Collection("Friends");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...